变量的截取,字符的替换、数组的排序:
实例
<?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);
运行实例 »
点击 "运行实例" 按钮查看在线实例
总结:今天作业不难,还是困难在function