attaboy Posted January 22, 2012 Share Posted January 22, 2012 I'm trying to create a multidimensional array of movies organized by genre. This should take the form of an associative array with genres as keys. Each of the arrays elements should be an array containing movie names. This is what I have: <?php $movies = array( array("SF" => "", "Terminator", "Soylent Green", "I Robot", "frankenstein"), array("horror" => "exorcist", "IT", "frankenstein"), array("comedy" => "holy grail", "blazing saddles", "young frankenstein") ); //echo $movies[0][0]."<br>"; //echo $movies[1][0]."<br>"; //echo $movies[2][0]; foreach ($movies as $c) { while (list($k, $v) = each ($c)) { echo "$k ... $v <br/>"; } } ?> this is the output: SF ... 0 ... Terminator 1 ... Soylent Green 2 ... I Robot 3 ... frankenstein horror ... exorcist 0 ... IT 1 ... frankenstein comedy ... holy grail 0 ... blazing saddles 1 ... young frankenstein you'll see Terminator is only listed as element 0 because there's an empty string in front of it. The first item in the array is liated as the value to the key while the second value is listed as element 0. It doesn't seem right to me. Quote Link to comment https://forums.phpfreaks.com/topic/255500-multidimensional-array-problrm/ Share on other sites More sharing options...
trq Posted January 22, 2012 Share Posted January 22, 2012 Your array is nothing like what you have described your looking for. $movies = array( "SF" => array("Terminator", "Soylent Green", "I Robot", "frankenstein"), "horror" => array("exorcist", "IT", "frankenstein"), "comedy" => array("holy grail", "blazing saddles", "young frankenstein") ); Quote Link to comment https://forums.phpfreaks.com/topic/255500-multidimensional-array-problrm/#findComment-1309979 Share on other sites More sharing options...
attaboy Posted January 22, 2012 Author Share Posted January 22, 2012 Thank you so much!!! I thought I tried that, obviously I did something wrong but now it works as intended. Quote Link to comment https://forums.phpfreaks.com/topic/255500-multidimensional-array-problrm/#findComment-1310061 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.