Solved

Display Array

Posted on 2011-09-11
4
210 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 109

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

773 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