3.PHP条件语句及其字符串相关函数
PHP條件語句
<?php
????$number?=?rand(1,100);
????if($number?%?2?==?0){
????????echo?"%2";
????}else?if($number?%?3?==?0){
????????echo?"%3";
????}else{
????????echo?"??";
????}
????echo?"<p>";
????switch($number){
????????case?1:
????????????echo?"1";
????????????break;
????????case?2:
????????????echo?"2";
????????????bareak;
????????default:
????????????echo?"another";
????}
????echo?"<p>";
????$number?=?1;
????while($number?<=?10){
????????echo?$number."<p>";
????????$number?++;
????}
????echo?"<p>";
????$number?=?1;
????do{
????????echo?"1<p>";
????}while($number++?<=?10);
????for($i?=?0?;$i?<?10?;$i?++){
????????echo?"$i"."<p>";
????}
????$arr?=?array(1,2,3,4);
????foreach(?$arr?as?$i){
????????echo?$i."<p>";
????}
????foreach(?$arr?as?$i=>$j){
????????echo?$i."-".$j."<p>";
????}
?>
?
?
字符串相關:
<?php
????#去除字符串兩邊相關字母。
????$str?=?".!aaa!.";
????echo?trim($str?,".!")."<p>";
????echo?$str."<p>";
????#ltrim()?,rtrim();??只去除左邊或者右邊。
????#轉意?\*
????echo?"\"";
????#?addslashes()??用來為字符換str加入反斜線"\"。??還原stripslashes()
????#?addcslashes()在指定的字符串前加上反斜線。還原stripcslashes()
????$str?=?"12345";
????echo?strlen($str)."<p>";
????echo?substr($str,1,1)."<p>";
????#int?strcmp(?,?)?int?strnatcmp(?,)?strncmp
????$str?=?"1234556789";
????echo?strstr($str,"5")."<p>";
????echo?substr_count($str,"5")."<p>";
????#替換字符串?str_ireplace()函數??substr_rep;ace()
????#格式化字符串?number_format()
????#分割字符串?array?explode(...)
????#合成字符串?implode(...)
?>
?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的3.PHP条件语句及其字符串相关函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2.PHP语言基础
- 下一篇: 4.PHP正则表达式与数组