Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 11th, 2005, 05:56 AM
Registered User
 
Join Date: Feb 2005
Location: Male\', Henveiru, Maldives.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to macsham Send a message via MSN to macsham
Default Multidimensional Array

I want to create a multidimensional array of movies organized by genre. This should take the form of an associative array with genres as keys ("SF", "Action", "Romance", and so on). Each of this associative array's elements should be an array containing movie names ("2001", "Alien", "Terminator", and so on).
A Loop through the array , outputting each genre and its associated movies to the browser.

Also can mail me mazu@avasmail.com.mv
chao ;)
Macsham
  #2 (permalink)  
Old February 19th, 2005, 11:31 AM
Registered User
 
Join Date: Feb 2005
Location: Stalowa Wola, , Poland.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If u want to create this array:
Code:
<?php
$array = array("SF"=>array('film1', 'film2', 'film3', '...'), 'Action'=>array('film1', 'film2', 'film3', '...'));
?>
and then you can output it using this:
Code:
<?php
foreach($array as $key=>$cat) {
    echo '<B>' . $key . '</b><br />';
    foreach($array[$key] as $movie) {
        echo '&nbsp;&nbsp;&nbsp;--' . $movie . ',<br />';
    }
}
?>

  #3 (permalink)  
Old February 24th, 2005, 03:30 PM
Registered User
 
Join Date: Feb 2005
Location: Male\', Henveiru, Maldives.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to macsham Send a message via MSN to macsham
Default

Hi, thanx. I also found one some time back

$movies= array(
    array( name=>"<b>Sci Fixtion</b>",
        one=> "Matrix",
        two=> "Testube"),
    array( name=>"<b>Action</b>",
        two=> "America Black Jangiya",
        three=> "Flying Kik"),
    array( name=>"<b>Comedy</b>",
        one=> "Gods must be crazy",
        two=> "Sponge Bob"));

print "<B>LADIES AND GENTLEMEN WATCH MOVIES LIKE NEVER BEFORE</B><BR><BR>";

foreach ($movies as $num)
{
    foreach ($num as $name => $title)
    {
        print"$title<br>";
    }
    print "<br>";
}



Similar Threads
Thread Thread Starter Forum Replies Last Post
multidimensional array help for a newbie grahama PHP Databases 1 May 13th, 2008 09:41 AM
reading data from multidimensional array shish1 Beginning PHP 4 April 1st, 2007 06:42 PM
Multidimensional array in ch9 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 November 2nd, 2004 04:44 PM
Efficient implementation of multidimensional array Utwig C# 2 October 26th, 2004 04:34 AM
Multidimensional Array help grahama Beginning PHP 0 June 12th, 2004 09:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.