我的阵列如下。 我想把它搁置一半,从两个半部分中创造两个新的阵列。 然而,如果我使用阵列——slice,它就永远不会恢复。 我不理解为什么。
array
pic =>
array
0 => string 740 (length=3)
1 => string 741 (length=3)
2 => string 742 (length=3)
3 => string 748 (length=3)
alt =>
array
0 => string (length=0)
1 => string (length=0)
2 => string Test caption 1 (length=14)
3 => string Test caption 2 (length=14)
我需要的阵列应该保留钥匙,只有一半被搁置,因此,我有两个补充部分。 例如,上半部分应当考虑:
array
pic =>
array
0 => string 740 (length=3)
1 => string 741 (length=3)
alt =>
array
0 => string (length=0)
1 => string (length=0)
和后半期:
array
pic =>
array
0 => string 742 (length=3)
1 => string 748 (length=3)
alt =>
array
0 => string Test caption 1 (length=14)
1 => string Test caption 2 (length=14)
thanks
页: 1
$lodgepics = get_field( accommodation_rooms );
$featuredpics = get_field( featured_pics );
$showcasepics = array();
foreach ($featuredpics as $featuredpic) {
if (isset($featuredpic[ featured_pic ])&&!empty($featuredpic[ featured_pic ])) $showcasepics[pic][] = $featuredpic[ featured_pic ];
if (isset($featuredpic[ featured_alt ])) $showcasepics[alt][] = $featuredpic[ featured_alt ];
else $showcasepics[alt][] = ;
}
foreach ($lodgepics as $lodgepic) {
if(isset($lodgepic[ accommodation_roomphoto ])&&!empty($lodgepic[ accommodation_roomphoto ])) $showcasepics[pic][] = $lodgepic[ accommodation_roomphoto ];
if(isset($lodgepic[ accommodation_roomname ])&&!empty($lodgepic[ accommodation_roomname ])) $showcasepics[alt][] = $lodgepic[ accommodation_roomname ];
else $showcasepics[alt][] = ;
}