array help please, trying to echo out the entries of my multi dimentional array!

This is a discussion on array help please, trying to echo out the entries of my multi dimentional array! within the PHP forums, part of the Development category; I Have an array of data which i think is in the correct format and i am trying to pullout ...


Reply
 
LinkBack Thread Tools Display Modes
Old 20th January 2010, 05:14 PM   #1
Member
 
ljackson's Avatar
 
Join Date: Feb 2009
Location: Cornwall
Posts: 372
Thanks: 22
Thanked 3 Times in 3 Posts
ljackson is on a distinguished road
Expertise: PHP
Experience: Intermediate
Exclamation array help please, trying to echo out the entries of my multi dimentional array!

I Have an array of data which i think is in the correct format and i am trying to pullout each of the categories and their sub headings but nothing is displaying on the page?

here is my code
PHP Code:
    <?php
    
if($_SESSION['page'] == "entertainment")
    {
        
$category_list = array( 
                         
"Category" => array("DVD","CD","Video Games","Blu-Ray","Books"),
                            
"Sub" => array("The latest blockbuster DVDs.""Chart hit CDs from the hottest artists.","Top video games from all the major platforms including xbox 360, ps3, nintendo wii","The latest blockbuster Blu-Ray DVDs.","Bestselling hardback, paperback titles from the best authors")
                         );
    }
?>

    <div id="category_left">
    <?php
    $x
=0;
    foreach(
$category_list as $category){
    echo 
$category["Category"][$x];
    echo 
$category["Sub"][$x];
    
$x++;
    }
?>
    </div>
any ideas
Thanks
Luke
ljackson is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 20th January 2010, 08:11 PM   #2
Member
 
ljackson's Avatar
 
Join Date: Feb 2009
Location: Cornwall
Posts: 372
Thanks: 22
Thanked 3 Times in 3 Posts
ljackson is on a distinguished road
Expertise: PHP
Experience: Intermediate
Default

found a solution...

PHP Code:
    if($_SESSION['page'] == "entertainment")
    {
    $category_list = array();
    $category_list[] = array("category"=>"DVD","desc"=>"The latest blockbuster DVDs.");
    $category_list[] = array("category"=>"CD","desc"=>"Chart hit CDs from the hottest artists.");
    $category_list[] = array("category"=>"Video Games","desc"=>"Top video games from all the major platforms including xbox 360, ps3, nintendo wii");
    $category_list[] = array("category"=>"Blu-Ray","desc"=>"The latest blockbuster Blu-Ray DVDs.");
    $category_list[] = array("category"=>"Books","desc"=>"Bestselling hardback, paperback titles from the best authors");
    }?>

    <div id="category_left">
    <?php
    $x
=0;
    foreach(
$category_list as $category){
    echo 
$category["category"];
    echo 
"<br />";
    echo 
$category["desc"];
    echo 
"<br />";
    
$x++;
    }
ljackson is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Reply

Tags
array, dimentional, echo, entries, multi

Thread Tools
Display Modes