[Solved] Filling blank index value in array with another array [closed]


All you need to do, is to loop over the first array, check each value if it contains an null value and if so, take the first element of the second array, remove its first item and insert this where the null value is.

<?php
$arr1 = [
    0 => 'Data 1 Table 1',
    1 => null,
    2 => 'Data 2 Table 1',
    3 => null,
    4 => null,
    5 => 'Data 3 Table 1',
];

$arr2 = [
    0 => 'Data 1 Table 2',
    1 => 'Data 2 Table 2',
    2 => 'Data 3 Table 2',
];

foreach ($arr1 as $index => $value) {
    if (is_null($value)) {
        $arr1[$index] = array_shift($arr2);
    }
}

print_r($arr1);

2

solved Filling blank index value in array with another array [closed]