Code: Select all
<?php
function echo_variable(){
$args = func_get_args();
foreach($args AS $key => $val)
echo $key.' - '.$val.'<br>';
}
// test 1
$name = 'john';
$age = 20;
echo_variable($name, $age);
echo '<br>';
//test 2
$user = 'scoobydoo';
$mail = 'scobbydoo@hotmail.com';
echo_variable($user, $mail);
echo '<br>';
?>which is passed to the function as an argument.
The result of my test:
Code: Select all
// test1
0 - john
1 - 20
//test2
0 - scoobydoo
1 - scobbydoo@hotmail.comCode: Select all
// test1
name - john
age - 20
//test2
user - scoobydoo
mail - scobbydoo@hotmail.com