-1
How do I add the "favorite" array to the "colors" array"?
$a1['cores']=array("vermelho","amerelo","preto");
$a2['favoritas']=array("amerelo","preto");
I’ve tried with array_merge
array_merge($a1,$a2);
print_r($a1);
with array_push
array_push($a1,$a2);
print_r($a1);
but it won’t.
The result I want.
Array ( [cores] => Array ( [0] => vermelho [1] => amerelo [2] => preto [favoritas] => Array ( [0] => amerelo [1] => preto ) ) )
Do you need to declare 2 Arrays? If you do
$a['cores']=array("vermelho","amerelo","preto");
$a['favoritas']=array("amerelo","preto");
You will get the result unless you need the same two lists.– Rogerio Santos
Unfortunately it needs. :(
– stack full
Creates a third,
a3['cores'] = a1; a3['favoritas'] = a2;
– Rogerio Santos
Roger, there’s something wrong there. The result was Array ( [colors] => Array ( [colors] => Array ( [0] => red [1] => amerelo [2] => black ) [favorites] => Array ( [favorites] => Array ( [0] => amerelo [1] => black ) ) )
– stack full
Because you declare a1 and a2 with these indexes.. Now it’s easy.. hehe
– Rogerio Santos
I’m sorry, I don’t understand. but your answer doesn’t fit my question. I put your answer to run and it’s not equal(or similar) to what I want.
– stack full