1.Concertration operator: "."
ex.
<?php
$string="<b>Hello World!</b>";
$string2="This is a small world.";
echo $string." ".$string2;
?>
result:
Hello World! This is a small world.
2.String length: strlen()
ex.
<?php
$string="<b>Hello World!</b>";
echo strlen($string);
?>
result:
19
3.Switch:
ex.
<?php
$x=4;
switch($x)
{
case 1:
echo "1";
break;
case 2:
echo "2";
break;
default:
echo "not proper";
break;
}
?>
result:
not proper
4.array
ex.
<?php
$price = array("milk"=>200,"pen"=>25,"love"=>"can't be understood");
echo $price["milk"]."<br>";
echo $price["pen"]."<br>";
echo $price["love"]."<br>";
?>
result:
200
25
can't be understood
5.Multidimention array
ex.
<?php
$price = array("book"=>array(200,3000,50),
"pen"=>array(60,80),
"stone"=>array(0,5000,100000,"can't be understood"));
echo $price["book"][1]."<br>";
echo $price["pen"][0]."<br>";
echo $price["stone"][3]."<br>";
?>
result:
3000
60
can't be understood
6.for loop
ex.
<?php
$price = array("book"=>array(200,3000,50),
"pen"=>array(60,80),
"stone"=>array(0,5000,100000,"can't be understood"));
for($x=0;$price["book"][$x];++$x) echo $price['book'][$x]." ";
?>
result:
200 3000 50
7.foreach loop
For every loop iteration, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop iteration, you'll be looking at the next array value.
ex.
<?php
$price = array("book"=>array(200,3000,50),
"pen"=>array(60,80),
"stone"=>array(0,5000,100000,"can't be understood"));
foreach(array('book','pen','stone') as $item) echo $price[$item][0]." ";
?>
result:
200 60 0
8.function
ex.
<?php
$price = array("book"=>array(200,3000,50),
"pen"=>array(60,80),
"stone"=>array(0,5000,100000,"can't be understood"));
function cart($item_price,$number)
{
$sum=$item_price*$number;
echo "it cost $".$sum." in this category<br>";
return $sum;
}
echo "the total price is ".(cart($price['book'][1],3)+cart($price['stone'][2],2));
?>
result:
it cost $9000 in this category
it cost $200000 in this category
the total price is209000