Home > Backend Development > PHP Tutorial > PHP common functions

PHP common functions

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-30 13:31:43
Original
1090 people have browsed it

1) String

The main methods are: strops(), substr(), str_split(), explode(), etc. For more methods, check the PHP official manual;

<?php
/**
 * 字符串的方法:strpos()、substr()、print_r()、explode()
 */
$str="sun of beach";

//获取子字符串在当前字符串的索引位置
echo strpos($str,&#39;ea&#39;).&#39;<br/>';

//字符串的截取
$str1=substr($str,4);
$str2=substr($str,4,2);
echo $str1.'<br/>';
echo $str2.'<br/>';

//字符串的分割
$result1=str_split($str);
$result2=str_split($str,3);
$result3=explode(' ',$str);
print_r($result1);
echo '<br/>';
print_r($result2);
echo '<br/>';
print_r($result3);
echo '<br/>';

//字符串的连接
$num=500;
$str3="$str <br/>from Hanhan $num";
echo $str3;
Copy after login



2) Array

array_push() - used to store the value of the array;

For more methods, check out the PHP official manual;

<?php
//数组的创建:用索引创建
$arr=array();
$arr[0]='hello';
$arr[1]='php';
$arr[2]=100;
$arr[3]=3.14;
print_r($arr);
echo '<br/>';
echo $arr[2];
echo '<br/>';

//数组的创建:用key-value方式创建
$arr2=array();
$arr2['h']='hello';
$arr2['w']='world';
print_r($arr2);
echo '<br/>';
echo $arr2['h'];
echo '<br/>';

//数组的初始化
$arr3=array(0=>'jason',1=>'see','h'=>'hello','w'=>'world','name'=>'shydzc');
echo $arr3['name'];
echo '<br/>';

//数组的常用方法
$arr4=array();
for($i=0;$i<10;$i++){
    array_push($arr4,'item '.$i);
}
print_r($arr4);
Copy after login

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced the common functions of PHP, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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