rhyspaterson Posted June 30, 2008 Share Posted June 30, 2008 Hey guys, Quick question. Say i have two different arrays: $basic = array('a','b'); // and $multi = array( 'a' => array( 'apple', 'banana', ), 'b' => array( 'cherry', 'pineapple', ) ) Now, if i wanted to make a variable the same as a piece of data in the $basic array i would go: $x = 0; $variable = $basic[$x]; // $variable now equals 'a'. If i wanted to make a variable the same as a piece of data in the $multi array i would go: $x = 0; $variable = $multi['a'][$x]; // $variable now equals 'apple'. However! If i wanted to make $variable equal to the name of the multidimensional array (that is - a), how would i do it? I can't go: $x = 0; $variable = $multi[]; // breaks $variable = $multi[][]; // breaks $variable = $multi[$x]; // breaks I would like to be able to use a loop: for ($y=0; $y < 10; $y++) { $array_one[$y]=$multi[NAME OF the $Y $MULTI]; } Suggestions..? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 30, 2008 Share Posted June 30, 2008 Try this: <?php $multi = array( 'a' => array( 'apple', 'banana', ), 'b' => array( 'cherry', 'pineapple', ) ); foreach ($multi as $ary => $dmy) echo $ary . '<br>'; ?> Ken 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.