How to convert this array to string

array(3) {
[0]=> array(1) {
["Event"]=> array(5) {
["id"]=> string(3) "102"
["headline"]=> string(31) "Concert in the Park"
["message"]=> string(44) "The Band will be playing in the park on Saturday night"
["close_date"]=> string(10) "2012-06-17"
["start_date"]=> string(10) "2012-06-16"
} }

[1]=> array(1) {
["Event"]=> array(5) {
["id"]=> string(3) "102"
["headline"]=> string(31) "Comedy Night"
["message"]=> string(44) "Friday night comedy at Downtown Club"
["close_date"]=> string(10) "2012-06-15"
["start_date"]=> string(10) "2012-06-15"
} }

[2]=> array(1) {
["Event"]=> array(5) {
["id"]=> string(3) "102"
["headline"]=> string(31) "Fireworks Show"
["message"]=> string(44) "There will be a fireworks show after the baseball game"
["close_date"]=> string(10) "2012-07-4"
["start_date"]=> string(10) "2012-07-4"
} }
} 

I need $event[‘Event’][‘message’] from each array above into a single string, $my_events
Any assistance is appreciated. I’ve seen implode as well as foreach ($array as $key->$value) but don’t understand those implementations.

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
$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:

$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.

Yes! That’s super helpful. Thank you very much.