?
Solved

Display Array

Posted on 2011-09-11
4
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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 111

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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses

771 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