Blogger Information
Blog 56
fans 3
comment 1
visits 50824
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php变量作用域——2018年4月13日
沈斌的博客
Original
618 people have browsed it

php 变量作用域

实例

<?php
	
	$sitename='www.baidu.com';
	function hello(){
		//全局变量
		global $sitename;
		// 局部变量
		$name='world';
		return 'hello'.$name.$sitename;
	}

	echo hello();
	echo '<hr>';
	

	function myStatic(){
		//$num在函数执行完后,不被删除
		static $num=1;
		echo $num;
		$num++;
	}

	myStatic();
	echo "<br>";
	myStatic();

运行实例 »

点击 "运行实例" 按钮查看在线实例

is_null(),empty(),issset()


实例

<?php
	// is_null,变量没赋值;赋值null;unset()
	$var1;
	$var2=null;
	$var3='he';
	unset($var3);

	var_dump(is_null($var1));
	var_dump(is_null($var2));
	var_dump(is_null($var3));

	echo "<hr>";



	//empty(),空字符,空数组;null;0,'0',false.
	$str1='';
	$str2=[];
	$str3='0';
	$str4=0;
	$str5=null;
	$str6=false;
	$str7='hello';

	var_dump(empty($str1));
	var_dump(empty($str2));
	var_dump(empty($str3));
	var_dump(empty($str4));
	var_dump(empty($str5));
	var_dump(empty($str6));
	var_dump(empty($str7));

	echo "<hr>";

	//isset(),变量被设置且不为null
	$domain='php';
	$name=null;
	$job;

	var_dump(isset($domain));
	var_dump(isset($name));
	var_dump(isset($job));

运行实例 »

点击 "运行实例" 按钮查看在线实例


1.JPG

2.JPG

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