HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to PHPVariablesData TypesOperatorsStringsArraysAssociative ArraysConditions (if / else)Loops (for / foreach / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
Arithmetic ( + - * / % ** )round() / floor() / ceil()max() / min() / abs()rand() / mt_rand()
✍️ String
📋 Array
🔁 Condition & Loop
🧩 Function
🔄 Type & Conversion
PHP›REFERENCE›Numbers & Math
🔢

Numbers & Math

Arithmetic operations and mathematical functions.

CommandDescription
Arithmetic ( + - * / % ** )Four operations, remainder (%), and exponentiation (**).
round() / floor() / ceil()Rounding functions.
max() / min() / abs()Maximum / minimum / absolute value.
rand() / mt_rand()Generates a random integer.

Arithmetic ( + - * / % ** )

Try it yourself →

Four operations, remainder (%), and exponentiation (**).

Syntax

$a + $b, $a % $b, $a ** $b

Description

Standard mathematical operators. % gives the remainder, ** gives the exponent.

Example

<?php
echo 7 + 3;
echo "\n";
echo 7 % 2;
echo "\n";
echo 2 ** 10;

Expected output

10
1
1024

When to use?

Calculations, even/odd check (% 2).

round() / floor() / ceil()

Try it yourself →

Rounding functions.

Syntax

round($number, $digits)

Description

round rounds to the nearest, floor down, ceil up.

Example

<?php
echo round(3.14159, 2);
echo "\n";
echo floor(4.9);

Expected output

3.14
4

When to use?

Displaying money, averages.

max() / min() / abs()

Try it yourself →

Maximum / minimum / absolute value.

Syntax

max($a, $b, ...) · min(...) · abs($x)

Description

max gives the largest, min gives the smallest, abs gives the unsigned value. Also works with arrays.

Example

<?php
echo max(3, 9, 5);
echo "\n";
echo abs(-7);

Expected output

9
7

When to use?

Highest score, difference calculation.

rand() / mt_rand()

Try it yourself →

Generates a random integer.

Syntax

rand($min, $max)

Description

Returns a random number between min and max (inclusive). Changes on every run.

Example

<?php
$zar = rand(1, 6);
echo ($zar >= 1 && $zar <= 6) ? "ok" : "error";

Expected output

ok

When to use?

Dice rolls, random selection, games.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code