PHP array_merge if not empty
arrays, php, sorting
Solution
Okay here you go, this should do the trick (if you make array of the initial arrays):
$arrs = array();
$arrs[] = array('something1', something2);
$arrs[] = array('something3', something4);
$arrs[] = array();
$arrs[] = array('something1', something2);
$list = array();
foreach($arrs as $arr) {
if(is_array($arr)) {
$list = array_merge($list, $arr);
}
}
print_r($list);
Problem
Trying to merge 4 arrays, but some may be empty at certain times. ``` $array_1 = array('something1', something2); $array_2 = array('something3', something4); $array_3 = array(); $array_4 = array('something1', something2); $list = array_merge($array_1,$array_2,$array_3,$array_4); print_r($list); ``` But if one of the arrays are empty, there will be an error. I've been googling forever, but I can't find a solid simple answer on how to check for empty arrays before merging. Argument #2 is not an array Or whichever array is empty is the argument number. How do I strip out empty arrays before merging?