Creating a line of arrays

Hey,

My thinking is not working today, can anyone help me? I have this

if ($_POST['enable_life'])
$i['lf'] = z_life($z);

if ($_POST['enable_death'])
$i['dh'] = z_death($z);

if ($_POST['enable_sleep'])
$i['sp'] = z_sleep($z);

$total_sections = count($i);

// How do i merge the arrays that are not empty?
// So i can get them all in line to merge here?


if (count > 1)
{
/** This is the merged array, it needs to be more flexible */
$final_array = array_merge($i['fb'], $i['tw']); // How to get all the non-empty things in there?
}
else
{
	$final_array = $i[the_key_here];
}

So I’m assuming z_<whatever>() returns an array?

One thing to remember is that you want to ensure that those $_POST variables are sanitized and also cast the array type onto anything you use array_merge with because otherwise, you might have some issues: See the “Warning” here.

As far as your code is concerned, and assuming that function returns an array of some sort, it’s really just a matter of using some FOREACH routines (unless I’m mistaken). Also, wouldn’t you want to use ($total_sections >= 1) in your IF condition?