Jump to content


Photo

arrays within arrays within arrays ?


  • Please log in to reply
5 replies to this topic

#1 altergothen

altergothen
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 October 2006 - 11:19 AM

I want to be able to echo array items within an array within an array
Here is my array structure:
Please help!
Thanks.

Array
(
    [inside_image] =>
    [items] => Array
        (
            [0] => Array
                (
                    [title] => Bangladesh's Health Nutrition Program Gets 460 Mln USD (RedNova)
                    [link] => http://us.rd.yahoo.c...alth nutrition.
                    [description] => 10/19/2006 - European food companies are already being asked to ...
                )

            [1] => Array
                (
                    [title] => Member States start compiling health claims lists (Nutraingredients.com)
                    [link] => http://us.rd.yahoo.c.../SIG=12o66dneo¬†                                                                                
                    [description] => 10/19/2006 - European food companies are already being asked to ...
                )

            [2] => Array
                (
                    [title] => Good nutrition essential for bone health (Antara News)
                    [link] => http://us.rd.yahoo.c...n/SIG=11f9hhq9g
                    [description] => (Full text of a statement. Contact details below.)
                )

)

    [channel] => Array
        (
            [title] => Yahoo! News Search Results for health nutrition
        )

)

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 20 October 2006 - 12:02 PM

The easy part is walking the array, the hard part is knowing the format you need the results returned in! Left me explain that. The only time you really need to walk through an array is when you need to do something to the complete array, like remove slashes or set some elements that may have a certain value or maybe empty. In this case it's different, because you need to format the output as your running through the array. To do that, one needs to know how you want to format the output.


me!

#3 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 20 October 2006 - 12:17 PM

<?php
echo $array_name['items']['0']['title'];
echo $array_name['items']['0']['link'];
echo $array_name['items']['0']['description'];
?>

If you need to show each item you will needd to create a loop of some sort
Everything you want to know is here.

#4 altergothen

altergothen
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 October 2006 - 12:26 PM

Thanks a million Guys!

printf - please can you give me a formatted example?
thanks

#5 altergothen

altergothen
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 October 2006 - 12:34 PM

I think i figured it out? ..... Correct?
>
>
>
$title = $rss_array['items']['0']['title'];
$link =  $rss_array['items']['0']['link'];
$description =  $rss_array['items']['0']['description'];

echo "<p class='heading'><a href='$link'>$title</a></p><p class='text'>$description</p><a href='$link'>Read Full Article ...</a> ";
?>   

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 October 2006 - 12:37 PM

Yeah :)

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users