Blogger Information
Blog 57
fans 0
comment 0
visits 46942
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
变量的类型与转换
藍錄的博客
Original
615 people have browsed it

实例

<?php
echo '<h3>变量的类型与转换</h3>';
// 标量: 单值变量, 数值(整数,浮点),字符串,布尔(true/false),基本数据类型
// 复合类型: 多值变量,数组 Array, 对象Object
// 特殊类型: 资源,null

$age = 30;  // Integer
$salary = 3560.88;  // Float
$name = 'peter zhu'; // String
$isMarried = true; // Boolean

//echo $name . '的年龄是: '.$age. ',工资是: '.$salary. ',是否已婚: '. $isMarried. '<br>';
//echo $name,'的<span style="color:red">年龄</span>是: ',$age, ',工资是: ',$salary, ',是否已婚: ', $isMarried. '<hr>';

$books = ['php','mysql','html','css','javascript']; //Array
echo '<pre>';
//print_r($books);

$student = new stdClass();  // Object
$student->name = '罗盼';
$student->course = 'php';
$student->grade = 80;

//var_dump($student);
//var_dump($student->name);
//echo $student->name,'<br>';
//echo '<h3 style="color: blue">',print_r($student->name,true),'</h3>';
// 资源类型
$file = fopen('test.txt','r') or die('打开失败');
echo fread($file, filesize('test.txt'));
//fclose($file);

//null
$price = null;
echo '$price is ' . $price;
echo '<br>';

echo is_null($price) ? '是NULL' : '不是NULL';

//变量检测
// gettype()
echo gettype($file), '<hr>';  //resource

// 设置类型
$price = 124.99;
settype($price, 'integer');
echo $price, '<hr>';
echo gettype($price);

运行实例 »

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

 

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