Home > Backend Development > PHP Tutorial > php-PHP全局变量的问题global

php-PHP全局变量的问题global

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-02 11:31:21
Original
1021 people have browsed it

php全局变量global

代码链接:http://www.mcqyy.com/RunCode/php/#id/29b4699b9f37cc352dcf1e39c7491e86
代码:

<code> <?php $arr = array();main();array_push($arr,'2');arrSearch($arr,'2');arrSearch($arr,'1');function main(){    global $arr;    array_push($arr,'1');    arrSearch($arr,'1');}function arrSearch($arr,$el){    echo "<hr>";    echo "arr:";    print_r($arr);    echo "<br>";    echo $el.":";    if(array_search($el,$arr)){        echo 'yes';    }else{        echo 'no';    }}?></code>
Copy after login

结果是:
arr:Array ( [0] => 1 )
1:no
arr:Array ( [0] => 1 [1] => 2 )
2:yes
arr:Array ( [0] => 1 [1] => 2 )
1:no

ps:刚学php,还请大家指教。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template