2 回答

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個贊
你可以通過循環(huán)來做:foreach
$res = [];
foreach($array1 as $ind=>$num){
$res[$num] = $array2[$ind] === "" ? "No Value" : $array2[$ind];
}
print_r($res);
輸出:
Array
(
[1] => apple
[2] => banana
[3] => No Value
[4] => dog
[5] => No Value
)

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個贊
使用和array_map()array_combine()
<?php
$array1 = array("1","2","3","4","5");
$array2 = array("apple","banana","","dog","");
$array2 = array_map(function($v){
return (empty($v)) ? "No Value" : $v;
},$array2);
$key_value = array_combine($array1,$array2);
print_r($key_value);
https://3v4l.org/CY4ku
- 2 回答
- 0 關(guān)注
- 133 瀏覽
添加回答
舉報(bào)