在函数中访问全局变量的几种方法:关键字: global,预定义变量: $GLOBALS,参数传参数

原创 2019-01-06 16:36:23 271
摘要:<?php/*练习*/$thief = '张三';/*$GLOBALS*/function aa() {    $thief = $GLOBALS['thief'];    return isset($thief) ? 'yes' : 'no';}echo aa();echo '&

<?php

/*练习*/

$thief = '张三';

/*$GLOBALS*/

function aa() {

    $thief = $GLOBALS['thief'];

    return isset($thief) ? 'yes' : 'no';

}

echo aa();

echo '<hr>';


/*global*/

function bb() {

    global $thief;

    return isset($thief) ? 'yes' : 'no';

}

echo bb();

echo "<hr>";


/*传参数*/

function cc($f) {

    return isset($f) ? 'yes' : 'no';

}

echo cc($thief);


批改老师:灭绝师太批改时间:2019-01-06 16:45:45
老师总结:测试比较全面,知识点重在理解,用的不多但是需要掌握!

发布手记

热门词条