<?php
//Method 1
//Receive a series of parameters and output them one by one
function show_params () {
//Get the number of passed parameters
$count = func_num_args();
//Transfer the parameters and output them one by one
for ($i = 0; $i < $count; $i++) {
//Get parameters
$param = func_get_arg($i);
echo $param . PHP_EOL;
}
}
//Calling the function
show_params(1, 2, 'apple', 3.14);
//Method 2
function show_params () {
//Define an array that stores passed parameters
$params = array();
//Get all parameters
$params = func_get_args();
$count = count($params);
//Travel and output parameters one by one
for ($i = 0; $i < $count; $i++) {
echo $params[$i];
echo PHP_EOL;
}
}
//Note: Method 2 is executed slower than method 1