【问题标题】:Php doesn't supports global scope variables inside a function without using the global keyword?php 不支持函数内部的全局范围变量而不使用 global 关键字?
【发布时间】:2022-06-15 16:31:18
【问题描述】:
<?php
   $a ="helllo welcome to php! ....:)"; 
   function msg(){ 
       /* global $a; */
       echo $a;
   } 
   msg();
?>

全局变量 $a 在函数 msg() 中不可访问,但是当我使用全局 $a 时 那么它是可访问的,我想知道它是否可访问

Output
Code

【问题讨论】:

  • 你是对的。要么将变量作为参数传递给函数,要么使用 global 关键字允许它们进入函数范围

标签: php scope global-variables


猜你喜欢
  • 2013-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-10
  • 2017-03-05
  • 2016-11-13
  • 2020-10-02
相关资源
最近更新 更多