malikah Posted August 13, 2009 Share Posted August 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 13, 2009 Share Posted August 13, 2009 Remove this line: $bigArray[$i] = $valsOne[$i]; from your loop Alternatively use array_combine Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.