Solved

Display Array

Posted on 2011-09-11
4
207 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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
foreach( $array as $k => $v ) {
   echo $k .' - '. $v[36] .' - '. $v['pagetitle'] .' - '. $v[19] .' - '. $v[27] .'<br />';
}

Open in new window


HTH
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
Perfect - thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now