实例
<style type="text/css"> hr{ padding: 0px; margin: 5px 0px; width: 650px; } </style> <?php $test=array("JAVA","PHP","HTML","CSS","C++","Mysql"); print_r($test); echo "<hr>"; sort($test);//sort升序排列 print_r($test); echo "<hr>"; //sort降序排列 $test=array("JAVA","PHP","HTML","CSS","C++","Mysql"); rsort($test); print_r($test); echo "<hr color='gray'>"; $test2=array("Nginx"=>"2","IIS"=>"3","Apache"=>"1"); print_r($test2); echo "<hr>"; //asort根据值升序排列 asort($test2); print_r($test2); echo "<hr>"; //arsort根据值降序排列 $test2=array("Nginx"=>"2","IIS"=>"3","Apache"=>"1"); arsort($test2); print_r($test2); echo "<hr>"; //ksort根据键升序排列 $test2=array("Nginx"=>"2","IIS"=>"3","Apache"=>"1"); ksort($test2); print_r($test2); echo "<hr>"; //krsort根据键降序排列 $test2=array("Nginx"=>"2","IIS"=>"3","Apache"=>"1"); krsort($test2); print_r($test2); echo "<hr color='gray'>"; //长度 echo strlen(" www.php.cn中文网! "); echo('<hr color="gray">'); //替换 $test3="www.php.cn!"; echo str_replace("php","html",$test3); echo '<hr color="gray">'; $test4="hello"; echo('origin: '.$test4.'<br>'); echo('split: '); print_r(str_split($test4)); echo('<br>split by 2: '); print_r(str_split($test4,2)); echo '<hr color="gray">'; //分割 $str = 'test1,test2,test3,test4'; echo('origin: '.$str.'<br>'); print_r(explode(',',$str,2)); echo '<br>'; print_r(explode(',',$str,4)); echo '<br>'; print_r(explode(',',$str,-2)); echo '<hr color="gray">'; $str1=array("www",".php.cn"); echo implode("",$str1);
运行实例 »
点击 "运行实例" 按钮查看在线实例