Blogger Information
Blog 33
fans 0
comment 0
visits 24467
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组排序及字符串函数 2018年8月27日 23:00
EmonXu的博客
Original
542 people have browsed it

//编程1: 实例演示substr(),strstr(),strpos()函数
//编程2: 实例演示str_replace(), substr_replace()
//编程3: 实例演示: usort()二维数组的排序


实例

<?php
//编程1: 实例演示substr(),strstr(),strpos()函数
//编程2: 实例演示str_replace(), substr_replace()
//编程3: 实例演示: usort()二维数组的排序

$STRING='PHP\HTML\CSS';

echo substr($STRING,0,4),'<br>';

echo substr($STRING,4),'<br>';

echo substr($STRING,-3),'<br>';

echo '<hr>';

echo strstr($STRING,'html'),'<br>';

echo strstr($STRING,'HTML'),'<br>';

echo strstr($STRING,'HTML',true),'<br>';

echo strstr($STRING,'HTML',false),'<br>';

echo '<hr>';

echo strpos($STRING,'HTML'),'<br>';

echo substr($STRING,strpos($STRING,'HTML'),strlen('HTML'));

echo '<hr>';

echo substr_replace($STRING,'H5',4,4),'<br>';
echo substr_replace($STRING,'H5',4,0),'<br>';

echo '<hr>';

echo str_replace('HTML','H5',$STRING,$count),'<br>';

echo '替换了',$count,'次';

echo '<hr>';

$nba=[
    ['team'=>'勇士','win_num'=>40],
    ['team'=>'火箭','win_num'=>50],
    ['team'=>'骑士','win_num'=>50],
    ['team'=>'湖人','win_num'=>60]];

usort($nba,function ($a,$b){
    if($a['win_num']=$b['win_num']){
        return 0;
    }else {
        return $a['win_num'] > $b['win_num'] ? 1 : -1;
    }
});

echo var_export($nba,true);

运行实例 »

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


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