How to transform Array into different variables?

4

I have the following array which returns me the following values:

(
    [cliente] => Array
        (
            [0] => Array
                (
                    [Code] => 1
                    [Name] => a
                )

            [1] => Array
                (
                    [Code] => 2
                    [Name] => b
                )  
        )  
)

Is there a way I can get each Code to transform to a $stnCode variable and to each Name transform to $stnName ?

Because I want to insert into the database, where the Cliente table receives Code and Name .

    
asked by anonymous 22.10.2016 / 15:08

1 answer

4

You can scroll through $dados by indicating the cliente sub-array:

$dados = array('cliente' => array('0' => array('Code' => 1, 'Name' => 'a'),
                                  '1' => array('Code' => 2, 'Name' => 'b')));

foreach ($dados['cliente'] as $cliente) {
    $stnCode = $cliente['Code'];
    $stnName = $cliente['Name'];

    // Use $stnCode e $stnName aqui...

    echo $stnCode . ":" . $stnName . "\n";
}

See DEMO

    
22.10.2016 / 15:38