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(...)
?>