Blogger Information
Blog 64
fans 2
comment 3
visits 75744
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
字符串—2018年4月19日08:42:14
清雨的博客
Original
704 people have browsed it


实例

<?php
	$arr=['id'=>2,'name'=>"qingyu",'family'=>'php','grade'=>70,7=>true];

	echo "<pre>";

	echo "<p>未排序数组</p>";
	print_r($arr);

	echo "<hr>";

	// 数值类型排序

	// 字符类型排序
	sort($arr,SORT_STRING);
	print_r($arr);

	echo "<hr>";
	// 保留键名
	$arr=['id'=>4,'name'=>"qingyu",'family'=>'js','grade'=>70,7=>true];
	asort($arr);
	print_r($arr);

	echo "<hr>";
	$arr=['id'=>4,'name'=>"qingyu",'family'=>'js','grade'=>70,7=>true];
	// 对键名排序
	ksort($arr);
	print_r($arr);

	echo "<br>";
	$arr=['id'=>4,'name'=>"qingyu",'family'=>'js','grade'=>70,7=>true];

	// 反转排序
	rsort($arr,SORT_NUMERIC);
	
	print_r($arr);

	echo "<hr>";
	// 自定义排序
	$arr1=[10,4,55,3,22,99];
	usort($arr1,function($a,$b){
		if ($a>$b) {
			return false;
		} else if ($a == $b){
			return 0;
		} else {
			return true;
		}
	});
	print_r($arr1);

运行实例 »

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

效果图

1.png

字符串的查找与替换

实例

<?php
	$s = 'hello欢迎您使用';
	echo strlen($s),'<br>';
	echo mb_strlen($s,"UTF-8");

	// 字符串与数组转换
	$str='html,js,php,jquery';
	echo "<pre>";
	// str_split
	print_r(str_split($str));

	// explode
	print_r(explode(',',$str));
	// 指定分割的长度
	print_r(explode(',',$str,3));

	// implode,返回字符串
	$arr1=explode(',', $str);
	echo implode(',',$arr1),'<br>';
	echo implode('*',$arr1);


	echo "<hr>";
	// 字符串的查找替换
	$arr='1234567890';
    echo '<p>0的位置</p>';
	echo strpos($arr,'0'),'<br>';
	echo '<hr>';
    echo '<p>返回子串04后面部分</p>';
	echo strstr($arr,'04'),'<br>';
	echo '<hr>';
	echo '<p>返回子串04前面部分</p>';
	echo strstr($arr,'04',true),'<br>';
	echo '<hr>';
    echo '<p>查找带有04的字符替换为**</p>';
	echo str_replace('04','**',$arr),'<br>';
    echo '<hr>';
	echo '<p>第3个索引起,四个字符替换为****</p>';
	echo substr_replace($arr,'****',3,4);

运行实例 »

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


Correction status:Uncorrected

Teacher's comments:
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