php variable scope code example
Example 1: php variable parameters
<?php
function some_func($a, $b) {
for ($i = 0; $i < func_num_args(); ++$i) {
$param = func_get_arg($i);
echo "Received parameter $param.\n";
}
}
function some_other_func($a, $b) {
$param = func_get_args();
$param = join(", ", $param);
echo "Received parameters: $param.\n";
}
some_func(1,2,3,4,5,6,7,8);
some_other_func(1,2,3,4,5,6,7,8);
?>
Example 2: php variables
<?php
$output = ' Hello there Bob!!';
$num1 = 4;
$num2 =10;
$sum = $num1 + $num2;
$string1 = ' Hello';
$string2 = 'Bobby!!';
$greeting = $string1 .' '. $string2;
$greeting2 = "$string1 $string2";
$string3 = ' They\'re Here';
define('GREETING', ' Hello Everyone!!');
echo $sum;
echo $output;
echo $greeting;
echo $greeting2;
echo $string3;
echo GREETING;
?>