Transform array and String

2

How do I transform an array similar to this and Strings to write each row in the Mysql database.

I will only need the data of each array (date, site and Status)

print_r($arrayOut);

Array
(
    [1] => Array
        (
            [date] => 15/12/2016 17:11
            [site] => AC SAO MIGUEL DOS CAMPOS - Sao Miguel Dos Campos/AL
            [status] => Endereço insuficiente para entrega
            [isOrigin] => 1
        )

    [2] => Array
        (
            [date] => 15/12/2016 17:11
            [site] => Objeto em devolução ao remetente  
            [status] => Endereço insuficiente para entrega
            [isOrigin] => 
        )

    [3] => Array
        (
            [date] => 15/12/2016 09:53
            [site] => Sao Miguel Dos Campos/AL
            [status] => Saiu para entrega ao destinatário
            [isOrigin] => 1
        )

    [4] => Array
        (
            [date] => 09/12/2016 17:08
            [site] => AGF JARDIM MARILIA - Sao Paulo/SP
            [status] => Postado
            [isOrigin] => 1
        )

)
    
asked by anonymous 20.12.2016 / 15:50

1 answer

3

You can use json_encode to convert to string.

$dataString = json_encode($arrayOut);

If you want to take some fields, before using json_encode loop and take the fields you do not want:

foreach($arrayOut as $arr) {

    unset($arr['isOrigin']);

}

If you want to save one at a time in the database, just use foreach :

foreach($arrayOut as $arr) {

    unset($arr['isOrigin']);
    $dataString = json_encode($arr);
    // inserir $dataString na coluna correspondente.

}

json_encode

    
20.12.2016 / 15:58