How to add information inside php array?

0

I have the following php array:

$postFields = array(    
        'email' => '[email protected]',
        'token' => '123456',

        /*INSERIR AQUI*/

);

Where it says "insert here", I need to insert additional information dynamically, which would be the following:

'item1' => 'Nome1'
'valor1' => '01',
'item2' => 'Nome2'
'valor2' => '02',
.....
'itemN' => 'NomeN',
'valorN' => '999'

. How do I add these values into the array above?

    
asked by anonymous 20.04.2018 / 15:07

1 answer

1

Try this:

$postFields["item1"]  = "Nome1";
$postFields['valor1'] = "01";
$postFields["item2"]  = "nome2";
$postFields["valor2"] = "02";
$postFields["itemN"]  = "NomeN";
$postFields["valorN"] = "999";

"item1" goes as index and "Name1" as value.

Al to add the other values you place this code inside a foreach and add one by one.

    
20.04.2018 / 15:13