【发布时间】:2021-05-22 05:31:50
【问题描述】:
我只想在值存在的情况下合并数据。示例:
// array 1
array:4 [▼
0 => "qwfd"
1 => "qw2e3"
2 => null
3 => null
]
// array 2
array:4 [▼
0 => "qwef"
1 => "w2"
2 => null
3 => null
]
我需要忽略两个数组中的2=> 和3=>,因为它们都是空的。
Ps即使其中一个为null也需要忽略(示例)
// array 1
array:4 [▼
0 => "qwfd"
1 => "qw2e3"
2 => "i am here"
3 => null
]
// array 2
array:4 [▼
0 => "qwef"
1 => "w2"
2 => null
3 => null
]
在这种情况下,数组1、2=> 具有值,但因为数组2、2=> 没有。也不应该合并。
My code
$names = $request->input('social_media_name'); // array 1
$usernames = $request->input('social_media_username'); // array 2
$newArray = array_combine($names, $usernames);
有什么想法吗?
【问题讨论】:
标签: php arrays array-combine