pikemsu28 Posted February 6, 2007 Share Posted February 6, 2007 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 More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 <?php function foo(&$array) { //insert your loop code here } ?> That will modify the array. I'm assuming you're only going to put the loop code in there. Then once you get an explode the array just call "foo($array);", and your array will be modified. Link to comment https://forums.phpfreaks.com/topic/37334-multiple-arrays/#findComment-178476 Share on other sites More sharing options...
pikemsu28 Posted February 6, 2007 Author Share Posted February 6, 2007 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 More sharing options...
Balmung-San Posted February 6, 2007 Share Posted February 6, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.