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..? Link to comment https://forums.phpfreaks.com/topic/112524-solved-basic-multidimensional-array-query/ 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 Link to comment https://forums.phpfreaks.com/topic/112524-solved-basic-multidimensional-array-query/#findComment-577778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.