Search code examples
phpmysqlarraysbarcode

How to send barcode details to database using a php array


I want to send barcode details to a database using a PHP array and want to create tables in the database according to barcode details. for example;

barcode number: D2D6000001

Here 1st D indicates the product type, 2 indicates production line, 2nd D indicates the month, 6 indicates the year and the last 6 numbers indicate product no.

I want to send each one into separate tables in the database using a PHP array. Can someone help me with this?


Solution

  • try below script:

    <?php
    $ReciveBarcode = "D2D6000001";
    $GETBARCODE = str_split($ReciveBarcode,5);
    
    $SepratedDetails['productType'] = $GETBARCODE[0][0];
    $SepratedDetails['productionLine'] = $GETBARCODE[0][1];
    $SepratedDetails['month'] = $GETBARCODE[0][2];
    $SepratedDetails['year'] = $GETBARCODE[0][3];
    $SepratedDetails['productNumber'] = $GETBARCODE[1];
    
    echo "<pre>";print_r($SepratedDetails);
    ?>
    

    output:

    Array
    (
        [productType] => D
        [productionLine] => 2
        [month] => D
        [year] => 6
        [productNumber] => 00001
    )