Blogger Information
Blog 5
fans 0
comment 0
visits 3257
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP中的数据类型转换永久转换
Wuy丶
Original
493 people have browsed it
<?php
	
	//设置错误级别。E_ALL但是除了NOTICE
	error_reporting(E_ALL&~E_NOTICE);

	//永久转换
	//得到变量的类型

	$var = 123;
	
	var_dump($var);
	
	echo gettype($var);
	
	echo '<br>';
		
	$var = true;
	
	echo gettype($var);

	echo '<br>';
		
	//永久转换settype($var,$type)
	
	$var = 123;
	
	var_dump($var);
	
	//对$var做了一个手术,变成布尔类型
	settype($var,'bool');

	var_dump($var);

	/*
	 * type 的可能值为:
		“boolean” (或为“bool”,从 PHP 4.2.0 起)
		“integer” (或为“int”,从 PHP 4.2.0 起)
		“float” (只在 PHP 4.2.0 之后可以使用,对于旧版本中使用的“double”现已停用)
		"string"
		"array"
		"object"
		“null” (从 PHP 4.2.0 起)
	 * 
	 */
	
	$var = '3king';
	
	settype($var,'int');
	
	var_dump($var);

	echo '<br>';
		
	/*
	 *
	 * PHP Warning(警告):  settype(): Invalid(非法) type in I:\WWW\PHPjicurumen\type-5.php on line 56
	 * 
	 */
	
	$var = 12.3;
	
	//手术失败
	
	settype($var,'king');
	
	var_dump($var);


?>


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!