There are many ways, but the simplest to understand is a foreach combined with an implode. Don't worry, I'll show you how it works.
PHP Code:
<?php
$eventMessages = array();
foreach($event as $eventItem){
$eventMessages[] = $eventItem['Event']['message'];
}
$my_events = implode(', ', $eventMessages);
The foreach() loops through the items in $event. So $event is an array with 3 items in; The loop sets $eventItem to each successive item every time it runs (which is equal to how many items are in the $event array). All I've done above is built up the $eventMessages array from this loop - each time the loop progresses, it adds the next $event's message.
The implode() then glues all of the $eventMessages together with a comma and space inbetween each.
The foreach, if you're not familiar with it, is not a scary thing. The above code is the same as below when there are 3 items in the array:
PHP Code:
$eventMessages = array();
$eventItem = $events[0];
$eventMessages[] = $eventItem['Event']['message'];
$eventItem = $events[1];
$eventMessages[] = $eventItem['Event']['message'];
$eventItem = $events[2];
$eventMessages[] = $eventItem['Event']['message'];
$my_events = implode(', ', $eventMessages);
Of course when there are 4 items, it runs 4 times instead of 3 and so on.
Hope that helps.
Bookmarks