Blogger Information
Blog 5
fans 0
comment 0
visits 5484
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
如何在函数中访问全局变量
小邓的博客
Original
2052 people have browsed it

<?php
// 局部变量 函数内部
function demo1()
{
   $str1 = "我是demo1中的变量str1";
   return $str1;
}
//在 外部访问
//echo $str1;
// 在函数内部访问
//echo demo1();



// 全局变量 在函数外部
$str2 = "我是demo2中的外部变量str1";
function demo2()
{
   return $str2 ? : '不可访问';
}
//echo demo2();
//echo $str2;

// 局部变量,在函数参数列表中定义
//function demo3($str3)
//{
//    return $str3;
//}
//echo '<hr />';
//echo demo3('杨过');

// 局部变量,在函数参数列表中定义,只能在函数内部访问
function demo3()
{
   $str3 = func_get_arg(0);
   $str4 = func_get_arg(1);
   return $str3 .'和'.$str4;
}

echo demo3('小龙女','尹志平');

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post