How to get the result separated by ,?
$getMusicList =explode(',', $event[0]['even_music']);
print_r($getMusicList);
this line gives
Array
(
[0] => 3
[1] => 12
[2] => 5
)
$exeGetMusic1 = array();
foreach ($getMusicList as $kk => $musicList) {
$getMusic = "select event_music_nam FROM et_mc
WHERE eventmusic_id='".$musicList."'";
$exeGetMusic = execute_query($getMusic, false, "select");
$exeGetMusic1[] = $exeGetMusic;
}
print_r($exeGetMusic1);
this line gives
Array
(
[0] => Array
(
[event_music_nam] => Alternative
)
[1] => Array
(
[event_music_nam] => Classics
)
[2] => Array
(
[event_music_nam] => Country/Folk
)
)
But I want to the final ans should be like this
Alternative,Classic开发者_运维问答s,Country/Folk
plz help. thanks
When there is only one item in sub array then why are you creating sub array at all, manage them in single dimension array. follow the below
Replace the last line of foreach $exeGetMusic1[] = $exeGetMusic;
with the line below
$exeGetMusic1[] = $exeGetMusic['event_music_nam'];
and replace print_r($exeGetMusic1);
with this line
echo implode(',',$exeGetMusic1);
$output = array();
foreach ($exeGetMusic1 as $music)
$output[] = $music['event_music_nam'];
echo implode(',', $output);
$result = implode(',', array_map(function ($item) {
return $item['event_music_nam'];
}, $exeGetMusic1));
Or (if you don't care how $execGetMusic1
looks like) replace
$exeGetMusic1[] = $exeGetMusic;
within the loop with
$exeGetMusic1[] = $exeGetMusic['event_music_nam'];
and then implode()
everything together
$result = implode(',', $exeGetMusic1);
精彩评论