Solved

Display Array

Posted on 2011-09-11
4
212 Views
Last Modified: 2012-05-12
This should be a simple one, but am having difficulties. I have this array:


Array
(
    [81] => Array
        (
            [36] => No
            [pagetitle] => Registration and Hospitality open
            [19] => 8:00 AM
        )

    [82] => Array
        (
            [36] => No
            [pagetitle] => Workshops
            [19] => 8:30 AM
        )

    [207] => Array
        (
            [24] => Workshop
            [pagetitle] => Creating, Growing and Managing a Chapter Endowment
            [19] => 8:30 AM
            [27] => 227
        )
)


And want to display the data like this:

81 - No - Registration and Hospitality open - 8:00 AM - -
82 - No - Workshops - 8:30 AM - -
207 - - Creating, Growing and Managing a Chapter Endowment - 8:30 AM - 227


Thanks in Advance!
0
Comment
Question by:spcjcp
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36519492
Try this out:

echo "<pre>";

foreach ($source as $key => $value) {
   echo "$key -";
   
   foreach ($value as $v) {
      echo " - $v";
   }
   
   echo "\n";
}

 
echo "</pre>";

Open in new window


Where $source represents the original array.
0
 
LVL 10

Accepted Solution

by:
Derokorian earned 250 total points
ID: 36519500
foreach( $array as $k => $v ) {
   echo $k .' - '. $v[36] .' - '. $v['pagetitle'] .' - '. $v[19] .' - '. $v[27] .'<br />';
}

Open in new window


HTH
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36519540
Do you really want the double dashes at the end of the strings?  You might consider using implode(' - ', $v) on the sub-arrays to make a display string with dashes between the data elements.
0
 

Author Closing Comment

by:spcjcp
ID: 36519625
Perfect - thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question