变量变量和变量函数

/**********by garcon1986***********/

<?php
//变量函数:当一个变量后有圆括号,php将寻找与变量的值同名的函数,并且尝试执行它。

function toto(){
    echo "toto function";
}
$to = 'toto';
$to();
echo '<br />';

function tata($t){
    echo "tata's variable is $t";
}
$ta = 'tata';
$ta('name');
echo '<br />';

function titi($i = ''){
    echo "titi's arguments is $i";
}
$ti = 'titi';
$ti('a');
echo '<br />';

function odd_number($x){
    echo '$x is odd';
}
function even_number($x){
    echo '$x is even';
}
$n = 10;
$oe = ($n % 2 ? 'odd_number' : 'even_number');
$oe($n);
echo '<br />';

//可变变量
  $Bar = "a";
  $Foo = "Bar";
  $World = "Foo";
  $Hello = "World";
  $a = "Hello";

echo  $a.'<br />'; //Returns Hello
echo  $$a.'<br />'; //Returns World
echo  $$$a.'<br />'; //Returns Foo
echo  $$$$a.'<br />'; //Returns Bar
echo  $$$$$a.'<br />'; //Returns a

echo  $$$$$$a.'<br />'; //Returns Hello
echo  $$$$$$$a.'<br />'; //Returns World

$a = 10;
$b = 'a';
echo $$b;
echo '<br />';
echo ${$b};
echo '<br />';

 
?>

你可能感兴趣的:(PHP,function)