这是获取数组中数据的foreach循环。
foreach ($data['songsPlayList'] as $key => $value){
$data['playlistSongs'] = $this->_song->getSongsInPlaylist($value);
//var_dump($data['playlistSongs']);
}
如果我查看来源,我会看到:
array(1) {
[0]=>
array(8) {
["id"]=>
string(3) "121"
[0]=>
string(3) "121"
["artist"]=>
string(12) "2face Idibia"
[1]=>
string(12) "2face Idibia"
["song_title"]=>
string(13) "African Queen"
[2]=>
string(13) "African Queen"
["filename"]=>
string(30) "2face Idibia-African Queen.mp3"
[3]=>
string(30) "2face Idibia-African Queen.mp3"
}
}
array(1) {
[0]=>
array(8) {
["id"]=>
string(3) "493"
[0]=>
string(3) "493"
["artist"]=>
string(10) "Lucky Dube"
[1]=>
string(10) "Lucky Dube"
["song_title"]=>
string(11) "Remember Me"
[2]=>
string(11) "Remember Me"
["filename"]=>
string(26) "Lucky Dube-Remember Me.mp3"
[3]=>
string(26) "Lucky Dube-Remember Me.mp3"
}
}
有了这个,我只能打印出一个数组的结果。所以我想做的是将它转换为这样的数组:
array(437) {
[0]=>
array(12) {
["id"]=>
string(3) "121"
[0]=>
string(3) "121"
["artist"]=>
string(12) "2face Idibia"
[1]=>
string(12) "2face Idibia"
["song_title"]=>
string(13) "African Queen"
[2]=>
string(13) "African Queen"
["filename"]=>
string(30) "2face Idibia-African Queen.mp3"
[3]=>
string(30) "2face Idibia-African Queen.mp3"
}
[1]=>
array(12) {
["id"]=>
string(3) "493"
[0]=>
string(3) "493"
["artist"]=>
string(10) "Lucky Dube"
[1]=>
string(10) "Lucky Dube"
["song_title"]=>
string(11) "Remember Me"
[2]=>
string(11) "Remember Me"
["filename"]=>
string(26) "Lucky Dube-Remember Me.mp3"
[3]=>
string(26) "Lucky Dube-Remember Me.mp3"
}
}
所以我可以做一个php foreach循环来获取所有结果数据。有什么建议吗?
答案 0 :(得分:0)
MESSAGE(STATUS "Checking ${CMAKE_OSX_SYSROOT}/usr/lib/libSystem.B.dylib for possible architectures")
其他解决方案:
$data['playlistSongs'] = [];
foreach ($data['songsPlayList'] as $key => $value){
$data['playlistSongs'][] = $this->_song->getSongsInPlaylist($value);
}
var_dump($data['playlistSongs']);