Jump to content

[SOLVED] Associative array


malikah

Recommended Posts

I'm trying to create an associative array:

 

$valsOne = array("A","B","C","D","E");
$valsTwo = array("apple","orange","grape","kiwi","banana");

for($i=0;$i<sizeof($valsOne);$i++)
{
$bigArray[$i] = $valsOne[$i];
$bigArray[$valsOne[$i]] = $valsTwo[$i];
}

foreach($bigArray as $key => $value)
echo $key . "=" . $value . "<br />";

 

I was hoping that the output would show the letter and then the fruit, but instead I get this:

0=A
A=apple
1=B
B=orange
2=C
C=grape
3=D
D=kiwi
4=E
E=banana

 

What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/170090-solved-associative-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.