我会给你快速的跑掉我正在做的事情.
我正在使用wordpress与advanced custom fields插件.这是一个基于php的问题,因为这些get_field()字段包含对象数组.
$gallery_location = get_field('gallery_location');
$gallery_studio = get_field('gallery_studio');
例如$gallery_location当转储将返回此…
array(18) {
[0]=>
array(10) {
["id"]=>
int(126)
["alt"]=>
string(0) ""
["title"]=>
string(33) "CBR1000RR STD Supersport 2014 001"
["caption"]=>
string(0) ""
["description"]=>
string(0) ""
["mime_type"]=>
string(10) "image/jpeg"
["url"]=>
string(94) "http://www.example.com/wp/wp-content/uploads/2013/10/CBR1000RR-STD-Supersport-2014-001.jpg"
["width"]=>
int(7360)
["height"]=>
int(4912)
}
... on so fourth
}
然后我使用merge_array来合并两个对象…
$gallery_location = get_field('gallery_location');
$gallery_studio = get_field('gallery_studio');
$downloads = array_merge( $gallery_location, $gallery_studio );
我正在合并多个数组,但如果其中一个数组为空,那么这将导致合并数组完全返回null!
我的问题是如何停止merge_array返回null是一些数组是空的?
提前感谢任何想法.
@zessx
这是我回来的
$gallery_location = get_field( 'gallery_location' );
$gallery_studio = get_field( 'gallery_studio' );
$downloads = array_merge( $gallery_location, $gallery_studio );
var_dump($gallery_location);
var_dump($gallery_studio);
var_dump($downloads);
这些都是以同样的顺序排列的转储结果…
string(0) ""
array(18) {
[0]=>
array(10) {
["id"]=>
int(126)
["alt"]=>
string(0) ""
["title"]=>
string(33) "CBR1000RR STD Supersport 2014 001"
["caption"]=>
string(0) ""
["description"]=>
string(0) ""
["mime_type"]=>
string(10) "image/jpeg"
["url"]=>
string(94) "http://www.example.com/wp/wp-content/uploads/2013/10/CBR1000RR-STD-Supersport-2014-001.jpg"
["width"]=>
int(7360)
["height"]=>
int(4912)
}
... on so fourth
}
NULL
正如你可以看到$下载仍然返回null,如果我尝试使用您的解决方案下面它不起作用?