批改状态:未批改
老师批语:
1、子字符串查询函数:
<?php $str = 'All crows under the sun are black tianhong@.com'; // 从$str字符串中,第10个索引开始,取出四个字符 echo substr($str,10,4),'<br>'; // 查找出$str字符中的 @字符,并且@后面的内容取出 echo strstr($str,'@'),'<br>'; // 查找出$str字符中的 @字符,并且@前面的内容取出,不包含@ echo strstr($str,'@',true),'<br>'; // 查找出$str字符中的 under字符,并且把under的首字母索引取出 echo strpos($str,'under');// 10
点击 "运行实例" 按钮查看在线实例
2、字符串查找并替换:
<?php
$str = 'All crows under the sun are black tianhong@.com';
// 把$str变量中的 tianhong 字符 替换成 tian
echo str_replace('tianhong','tian',$str),'<br>';
// 把天弘字符插入到 $str变量字符的 0 索引位置,并且取出原有的 10个字符,一起打印
echo substr_replace($str,'天弘',0,10);
// 如果给一个参数,就只能打印出天弘二字,原有的字符没了
echo substr_replace($str,'天弘',0);点击 "运行实例" 按钮查看在线实例
3、多维数组的排序:
<?php
$stu = [
['name' => '依依','ID' => 8],
['name' => '哒哒','ID' => 6],
['name' => '痛痛','ID' => 9],
['name' => '哈哈','ID' => 5],
['name' => '咯咯','ID' => 2]
];
usort($stu,function ($m,$n){
// 比较 Id的值,进行排序,值的范围:0~9
return strcmp($m['ID'],$n['ID']);
});
echo '<pre>';
echo var_export($stu);点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号