时间:2021-07-01 10:21:17 帮助过:15人阅读
<?php
/**
* 变量类型
* 字符串String
* 顺带介绍转义字符
*/
$int = 10; // 打印结果:10
$str2 = "a"; // 打印结果:a
$str3 = "this is a 'demo'"; // 打印结果:this is a 'demo'
$str4 = "this is a \"demo\""; // 打印结果:this is a "demo"
$str5 = "this is a $int"; // 打印结果:this is a 10
$str6 = 'this is a $int'; // 打印结果:this is a $int
//$str7 = "this is a $intttttt"; // 打印结果:会报错 , 因为没有这个变量
$str8 = "this is a {$int}ttttt,\\,\n,\r,\t"; // 打印结果:this is a 10ttttt,\, , ,
$str9 = 'this is a {$int}ttttt,\\,\n,\r,\t'; // 打印结果:this is a {$int}ttttt,\,\n,\r,\t
$str10 = <<<hello
<<<是定界字符串的内容,这里面随便写.....$int 出现 hello; 也不怕,因为需要顶格写,才表示结束
hello;
// 打印结果:<<<是定界字符串的内容,这里面随便写.....10 出现 hello; 也不怕,因为需要顶格写,才表示结束
/**
* 变量类型
* 数组Array
*/
$arr = array(1,2,3,4,5); // array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) }
/**
* 对象
* Object
*/
class Person{
var $name;
var $age;
var $sex;
function say(){
}
function eat(){
}
}
$person = new Person(); // object(Person)#1 (3) { ["name"]=> NULL ["age"]=> NULL ["sex"]=> NULL }
$person2 = new Person(); // object(Person)#2 (3) { ["name"]=> NULL ["age"]=> NULL ["sex"]=> NULL }
/**
* 资源
* ok.txt需要放在当前php所在目录下
* 如果文本中的内容是中文编码格式请使用UTF-8
* 在txt另存的时候可以看到编码选项
*/
$file = fopen("ok.txt","r"); // 现在显示的是ok.txt的内容
// if (NULL=="ok.txt"){
// printf("不存在<br>");
// }else{
// printf("存在<br>");
// }
echo $int;
echo "<br>";
echo $str2;
echo "<br>";
echo $str3;
echo "<br>";
echo $str4;
echo "<br>";
echo $str5;
echo "<br>";
echo $str6;
echo "<br>";
//echo $str7;
echo "<br>";
echo $str8;
echo "<br>";
echo $str9;
echo "<br>";
echo $str10;
echo "<br>";
var_dump($arr);
echo "<br>";
var_dump($person);
echo "<br>";
var_dump($person2);
echo "<br>";
echo fread($file,filesize("ok.txt"));
echo "<br>";
fclose($file); // 释放资源 以上就是Android程序员学PHP开发(6)-字符串数组对象资源-PhpStorm 的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!