PHP header

midcol2

If else betingelse

The answer is not true.
$var = 1;
if($var == 4)
{
echo "The answer is true.";
}
else
{
echo "The answer is not true.";
}

Switch betingelse

The number is 3
$X=3;
switch ($X)
{
case 1:
echo "The number is 1";
break;
case 2:
echo "The number is 2";
break;
case 3:
echo "The number is 3";
break;
default:
echo "Non of the numbers match";
}

While - do løkke

The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
$x=0;
while($x<=5)
{
echo "The number is " . $x . "
";
$x++; //Denne linje tæller x op med 1, for hver gang løkken gennemløbes.
}

Do - while løkke

The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10
The number is 11
The number is 12
The number is 13
The number is 14
The number is 15
The number is 16
$x=1;
do
{
$x++;
echo "The number is " . $x . "
";
} while ($x<=15);

For løkke

Number is 0
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
for ($x=0; $x<=5; $x++)
{
echo "Number is " . $x . "
";
}

Foreach løkke

$x[one] => 3.
$x[two] => 2.
$x[three] => 3.
$x[Four] => 3.
$x=array("one" => 1,"two" => 2,"three" => 3);
foreach ($x as $y => $value)
{
echo "\$x[$y] => $value.
";
}