Display Array

Posted on 2011-09-11
Last Modified: 2012-05-12
This should be a simple one, but am having difficulties. I have this 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!
Question by:spcjcp
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.
LVL 10

Accepted Solution

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

LVL 108

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.

Author Closing Comment

ID: 36519625
Perfect - thanks!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.
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 …

911 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

16 Experts available now in Live!

Get 1:1 Help Now