1. Multiple choice
<?php
$num=5;
switch($num%3)
{
case 0:
echo '十全十美';
break;
case 1:
echo '一帆风顺';
break;
default:
echo '两全其美';
break;
}
?>
2.循环
for,while,do while
for($i=1;$i<=10;$i++)
{
echo"{$i}:锄禾日当午<br>";
}
?>
foreach traverses the array:
$stu=array('berry','merry','rose');
foreach($stu as $v)
{
echo $v.'<br>';
}
foreach($stu as $key=>$value)
{
echo "($key)-($value)<br>";
}
3. Function
Predefined function:
is_int ();
custom function:
function show()
{
echo '锄禾日当午<br>';}
show();
function cal($num1,$num2)
{
$num=$num1+$num2;
echo "{$num}";}
cal(10,20);
function cal($num1,$num2)
{
$num=$num1+$num2;
echo "{$num}";
return $num;
}
echo cal(10,20);
4. Multidimensional array
$stu=array(
array('tom','yangyang','wanganshi'),
array('李白','dufu')
);
echo $stu[0][0];
$stu1=array(
array('tom'=>'111','yangyang'=>'222','wanganshi'=>'333'),
array('李白'=>'444','dufu'=>'555')
);
echo $stu1[0]['yangyang'];
5. The solution of garbled page
output Chinese garbled
text : the browser does not know the character encoding, add at the top of the entire page:
<meta charset="utf-8">
Or at the top of the php code
header('Content-Type:text/html;charset=utf-8');