我只想在值存在的情况下合并数据。例子:
// 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);
任何想法?