Blogger Information
Blog 43
fans 0
comment 0
visits 27006
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
变量的截取,替换和排序+2018年8月28日
Lee的博客
Original
651 people have browsed it

变量的截取,字符的替换、数组的排序:

实例

<?php
//1: 实例演示substr(),strstr(),strpos()函数
$webchat = '比微信好用的子弹短信火了!罗永浩:iPad版和PC版在做';
echo substr($webchat,3),'<br>';
echo substr($webchat,3,6),'<br>';
echo substr($webchat,-3),'<br>';

echo strstr($webchat,'!'),'<br>';
echo strstr($webchat,'!',true),'<br>';
echo strstr($webchat,'!',true),strstr($webchat,'!'),'<br>';

echo strpos($webchat,'罗永浩'),'<br>';

//2: 实例演示str_replace(), substr_replace()
$jia = '贾跃亭做到了!第一辆全功能FF91成功试产';
echo str_replace('FF91','FF92',$jia), '<br>';
echo str_replace(['贾','跃','亭'],['假','咬','停'],$jia), '<br>';

echo substr_replace($jia,'行',9,6), '<br>';

//3: 实例演示: usort()二维数组的排序

$arr = [['bank'=>'小米','model'=>'mi8'],
        ['bank'=>'红米','model'=>'note5'],
        ['bank'=>'红米','model'=>'6 PRO']
];
usort($arr,function ($m,$n){
    return strcmp($m['model'],$n['bank']);
});
echo '<pre>';
var_export($arr);

运行实例 »

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



QQ截图20180828155303.png

总结:今天作业不难,还是困难在function


Correction status:qualified

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