Development

Maths operators in PHP

Just like most languages you can use PHP to do Arithmetic equations like so:

echo (10 / 2);//5
echo (10 + 2);//12
echo (10 * 2);//20
echo (10 - 2);//8
echo (10 % 2);//0

$value = 50;
$value2 = 10;
echo ($value * $value2);//500
echo ($value - ($value + $value2));//10

To check if a value or variable is even use:

if (($var % 2) == 1)
{ echo "$var is odd." ;}
if (($a % 2) == 0)
{ echo "$var is even." ;}

To alternate a script output:

for ($i = 1; $i <= 10; $i++) {
  if(($i % 2) == 1)
    {echo "

$i is Even

";} else {echo "

$i is Odd

";} }

 

 

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

1 year ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

1 year ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

2 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

2 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

2 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

2 years ago