PHP拼接数组多个null,如果一个或多个数组为空,则php – merge_array返回null?

我会给你快速的跑掉我正在做的事情.

我正在使用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,如果我尝试使用您的解决方案下面它不起作用?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值