`
yanshaozhi
  • 浏览: 102679 次
  • 性别: Icon_minigender_1
  • 来自: 东营
社区版块
存档分类
最新评论

php basic

    博客分类:
  • php
阅读更多
$a = "a";
$b = &$a;

才是a , b 指向同一对象,不管ab谁变,他们两个都会变化

注:只有名称变量才可使用  &
$a=&(2+8) 是非法的

<?php
$a = 1;
$b = 2;

function Sum()
{
    global $a, $b;
    $b = $a + $b;
}
Sum();
echo $b;
?>

A second way to access variables from the global scope is to use the special PHP-defined $GLOBALS array. The previous example can be rewritten as:


Example #2 Using $GLOBALS instead of global

<?php
$a = 1;
$b = 2;

function Sum()
{
    $GLOBALS['b'] = $GLOBALS['a'] + $GLOBALS['b'];
}

Sum();
echo $b;
?>


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics