Correction status:Uncorrected
Teacher's comments:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>PHP 中数组的遍历</title> <link rel="stylesheet" href="http://1.meleezhao.applinzi.com/storm/ross.css"> </head> <body> <header>PHP 中数组的遍历</header> <div class="wrap"> <? $a = array('one','two','name',1,2,false,[11,22],true); echo '<div><p>sort() 对数组进行排序,默认按数值进行排序:<pre>'; sort($a); print_r($a); var_dump($a); echo '</pre></p>'; echo '<p>按ASSC 码值排序:<pre>'; sort($a,SORT_STRING); print_r($a); echo '</pre></p>'; $string = 'where are you'; echo '<p> 字符串长度方法: strlen()<pre>'; echo $string."\n"; echo '数组的长度是:',strlen($string); echo '</pre></p>'; //字符串与数组间的转换 $a2 = str_split($string); echo '<p>字符串转换成数组<pre>'; print_r($a2); echo '</pre></p>'; echo '<p><pre>'; $a3 = str_split($string,3); print_r($a3); echo '<br/>'; var_dump($a3); echo '</pre></p>'; echo '<p><pre>'; $a4 = explode(' ',$string); print_r($a4); echo '</pre></p>'; echo '</div>'; echo '<p>将数组转换为字符串</p>'; $a5 = array('long','time','no','see','!!'); $string2 = implode(' ',$a5); print_r($a5); echo '<hr>'; echo $string2; ?> </div> <footer>End..</footer> </body> </html>
点击 "运行实例" 按钮查看在线实例