如何在php中访问全局变量? [英] how to access global variables in php?

查看:91
本文介绍了如何在php中访问全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下



 <?php  
if(true){
global $ search ;
$ search = hello;
}
elseif(true)
{
echo $ search < /跨度>;
}
?>



我无法访问$ search值if()阻塞到elseif()块,是我的方法是错的?请任何人告诉我任何其他方式从一个块访问变量到另一个块,我需要在if()块中编写$ search变量,如下所示

 <?php  
$ search = hello; // 我不想像这样用,
if()
elseif()
?>

解决方案

search ;


search = 你好;
}
elseif(true)
{
echo

搜索;
}
?>



我无法访问


I have code like below

<?php
if(true){
  global $search;
  $search = "hello";
}
elseif(true)
{
echo $search;
}
?>


I am unable to access $search value from if() block to elseif() block, is my approach is wrong? please anyone tell me any other way to access variables from one block to another, i need to write $search variable in if() block not like below

<?php
$search = "hello";// I don't want to use like this, 
if()
elseif()
?>

解决方案

search;


search = "hello"; } elseif(true) { echo


search; } ?>


I am unable to access


这篇关于如何在php中访问全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆