SQL PHP HTML ASP JavaScript articles and free scripts to download
 

How to pass an array as input to an php function

In part I we have discussed how to return an array from a function. Here we will discuss how to input or pass an array to a function.




We will break an string and create an array. This created array we will pass as input to the function. To test the array inside the function we will display it by using while each command.




Here is the code.


function test($my_array){
while (list ($key, $val) = each ($my_array)) {
echo "$key -> $val <br>";
}

}

$collect_array=split(" ","Hello welcome to plus2net");
test($collect_array);


<< In the part I we discussed on how to return array from an php function.




Further readings
PHP Function
Declaring variables as global inside the function
Returning variable from a function
Returning an array from a function to main script
Array as input to a function










Join Our Email List
Email:  
For Email Newsletters you can trust
Functions
PHP Sections