Home > Backend Development > PHP Tutorial > 用二十秒记住几个PHP基础知识点

用二十秒记住几个PHP基础知识点

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:32:50
Original
972 people have browsed it

数组:
索引数组:数组的键是整数的数组,从0开始。
关联数组:数组的键是字符串的数组

//索引数组$arr=array('I','love','you');//关联数组$arr0=array('apple'=>"苹果",'yellow'=>"黄色");
Copy after login

foreach遍历数组

//数组的遍历$arr=array("苹果","黄色");foreach($arr as $key=>$value){    echo '<br>键是:'.$key.'对应的值是:'.$value;      }$arr0=array('apple'=>"苹果",'yellow'=>"黄色");foreach($arr0 as $key=>$value){    echo '<br>键是:'.$key.',对应的值是:'.$value;}
Copy after login

判断函数是否存在:function_exsits(函数名)

function sayHello(){    echo 'hello';}$test='sayHello';if(function_exsits($test)){    sayHello();}//输出hello
Copy after login

构造函数:对象创建时调用的方法
析构函数:对象销毁时调用的方法

class Car(){    public __construct(){        echo '对象已经创建';    }    public __destruct(){        echo '对象已经销毁';    }}$car=new Car();
Copy after login

strpos:查找字符串的方法

$str='hello world';echo strpos($str,'world');//输出6,从第6位开始
Copy after login

implode:返回值:把数组元素组合成一个字符串

$arr = array('abc', 'defg');$arr0 = implode('', $arr);print_r($arr0);//结果显示abcdefg
Copy after login

explode:返回值:函数返回由字符串组成的数组

$str="abc,defg";$arr=explode(',',$str);print_r($arr); //结果返回一个数组,里面有两个元素: abc和defg
Copy after login

本文作者:By:罗坚元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template