We accessing array items and print them
<!DOCTYPE html> <html> <body> <?php $cars = array("Volvo", "BMW", "Toyota"); echo $cars[2]; ?> </body> </html>
We accessing the item of associative array.
<!DOCTYPE html> <html> <body> <?php $car = array("brand"=>"Ford", "model"=>"Mustang", "year"=>1964); echo $car["model"]; ?> </body> </html>
We accessing the item of indexed array.
<!DOCTYPE html> <html> <body> <?php $cars = array("Volvo", "BMW", "Toyota"); echo $cars[0]; ?> </body> </html>
We adding a single line comment at the end of a line.
<!DOCTYPE html> <html> <body> <?php echo "Welcome Home!"; // Outputs a welcome message ?> </body> </html>
We creating a random integer between 10 and 100.
<!DOCTYPE html> <html> <body> <?php echo(rand(10, 100)); ?> </body> </html>
We are getting absolute (positive) value with the help of abs math function.
<html> <head> </head> <body> <?php $a=abs(-10); echo "$a <br>"; ?> </body> </html>