I am trying to create an array that will hold the only array that contains values.
Code below works well, but I get trouble if for ex, $array2 (but can array1 or array3) doesn't contain any value. In that case, I need to merge only array1 and array3.
$array3 = array_filter( array_map( function( $term ) {
if ( ! $term = \Softing\Term::get( $term ) ) {
return false;
}
return [
'link' => $term->get_link(),
'name' => $term->get_name(),
'color' => $term->get_color(),
];
}, $terms ) );
$formatted_terms[] = array_merge($array1, $array2, $array3);
Each if three arrays are formed on the same way as $array3, but some of them could be empty, no values. Those Arrays I dont want to merge. Want to create array only from arrays that holds value.
What is the easiest way to accomplish this.
I tried using
$formatted_terms[] = array_merge((array)$array1, (array)$array2, (array)$array3);
Any advice ?