Bellow是我的数组,包含空值 s
Array
(
[2] => Array
(
[1] => 2
[2] => 4
[3] => 9
)
[3] => Array
(
[1] => 4
[2] => 6
[3] =>
)
[4] => Array
(
[1] => 4
[2] => 6
[3] => 7
)
[5] => Array
(
[1] => 2
[2] => 4
[3] =>
)
[6] => Array
(
[1] =>
[2] => 6
[3] => 8
)
)
和波纹管是我的另一个数组,其中包含一些主索引3,5,6的值现在我希望波纹管数组的值(3,3,3)我想把上面的包含空值的数组请指导我如何根据主索引将波纹管数组值放在上面的数组空格
Array
(
[3] => Array
(
[2] => 3
)
[5] => Array
(
[4] => 3
)
[6] => Array
(
[2] => 3
)
)
所以在填充之后我想要像bellow一样的结果 所以对于清除我使用单引号显示填充值
阵 ( [2] =>排列 ( [1] => 2 [2] => 4 [3] => 9 )
[3] => Array
(
[1] => 4
[2] => 6
[3] => '3'
)
[4] => Array
(
[1] => 4
[2] => 6
[3] => 7
)
[5] => Array
(
[1] => 2
[2] => 4
[3] => ' 3'
)
[6] => Array
(
[1] => '3'
[2] => 6
[3] => 8
)
)
答案 0 :(得分:1)
试试这个
$array1 = [
2 => [1 => 2, 2=> 4, 3 => 9],
3 => [1 => 4, 2=> 6, 3 => null],
4 => [1 => 4, 2=> 6, 3 => 7],
5 => [1 => 2, 2=> 4, 3 => null],
6 => [1 => null, 2=> 6, 3 => 8]
];
$array2 = [
3 => [2 => 3],
5 => [4 => 3],
6 => [2 => 3]
];
foreach($array1 as $key => $value) {
if(true === array_key_exists($key, $array2)) {
foreach($value as $innerKey => $innerValue) {
if(null === $innerValue) {
$array1[$key][$innerKey] = '\''.current($array2[$key]).'\'';
}
}
}
}
var_dump($array1);
答案 1 :(得分:0)
你可以试试这个
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
mMovieAdapter.swap(viewHolder.getAdapterPosition(), target.getAdapterPosition());
return true;
}
这将在第一个数组上搜索空值。
$nulls = [
2 => [1 => 2, 2=> 4, 3 => 9],
3 => [1 => 4, 2=> 6, 3 => null],
4 => [1 => 4, 2=> 6, 3 => 7],
5 => [1 => 2, 2=> 4, 3 => null],
6 => [1 => null, 2=> 6, 3 => 8] ];
$fills= [3 => [2 => 3],5 => [4 => 3],6 => [2 => 3]];
foreach ( $fills as $key => $val ) {
$nulls[$key][array_search('',$nulls[$key])] = array_values($val)[0];
}
var_dump($nulls);
数组是您具有空值的数组,
$nulls
数组是一个数组,其中包含要填充的键的值
这将循环$fills
数组并搜索$fills
数组上的每个键并查找空值