How to add information in php array?

Asked

Viewed 100 times

0

Guys, I have the following php array:

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

        /*INSERIR AQUI*/

);

Where is written "insert here", I need to insert additional information dynamically, that would be these:

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

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

1 answer

2


Try it this way:

$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.

Ai to add the other values you put this code inside a foreach and add one to one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.