Jump to content

multiple arrays


pikemsu28

Recommended Posts

i have a form that has multiple arrays.  I know the basics on how to explode an array:

 

$array = explode('<>', $array);
for ($i="0"; $i<count($array); $i++)//check for empty string for term
{ 
	if(empty($array[$i])) 
	{
		unset($array[$i]);
	} 
}

 

what i want to do is turn this into a function so every array that i have i can call this function and not have to repeat the same 'for loop' for every array.  i haven't worked much with functions so a nice tutorial or a demo would be greatly appreciated. 

Link to comment
https://forums.phpfreaks.com/topic/37334-multiple-arrays/
Share on other sites

i will be able to use that function multiple times on one form right? 

 

function foo(&$array)
{
$unit = explode('<>', $unit);
for ($i="0"; $i<count($unit); $i++)//check for empty string for term
{ 
	if(empty($unit[$i])) 
	{
		unset($unit[$i]);
	} 
}
}
foo($array1); //able to echo the values in this array
foo($array2); //able to echo the values in array 2
so on an so forth??

Link to comment
https://forums.phpfreaks.com/topic/37334-multiple-arrays/#findComment-178547
Share on other sites

Actually, you're a bit off. $unit is not the variable you want to use in the function. You want to use $array. $unit is an undefined variable, while $array is an argument passed to the function.

 

foo($array1); will push $array1 through the process, unsetting all empty variables in the array. Though I don't know why you're calling explode inside the function. You can't explode an array.

Link to comment
https://forums.phpfreaks.com/topic/37334-multiple-arrays/#findComment-178552
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.