Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
Math Function Examples
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. Math Function Examples

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

Math Function Examples

PHP Math: abs() function

The abs() function returns absolute value of given number. It returns an integer value but if you pass floating point value, it returns a float value.

Syntax

number abs ( mixed $number ) 

 Example

<?php  
echo (abs(-7)."<br/>"); // 7 (integer)  
echo (abs(7)."<br/>"); //7 (integer)  
echo (abs(-7.2)."<br/>"); //7.2 (float/double)  
?> 

Output:

7 
7 

7.2
PHP Math: ceil() function

The ceil() function rounds fractions up.

Syntax

float ceil ( float $value )  

Example

<?php  
echo (ceil(3.3)."<br/>");// 4  
echo (ceil(7.333)."<br/>");// 8  
echo (ceil(-4.8)."<br/>");// -4  
?>  

Output:

4
8
-4
PHP Math: floor() function

The floor() function rounds fractions down.

Syntax

float floor ( float $value )  

Example

<?php  
echo (floor(3.3)."<br/>");// 3  
echo (floor(7.333)."<br/>");// 7  
echo (floor(-4.8)."<br/>");// -5  
?>  

Output:

3
7
-5

PHP Math: sqrt() function

The sqrt() function returns square root of given argument.

Syntax

float sqrt ( float $arg )  

Example

<?php  
echo (sqrt(16)."<br/>");// 4  
echo (sqrt(25)."<br/>");// 5  
echo (sqrt(7)."<br/>");// 2.6457513110646  
?>  

Output:

4
5
2.6457513110646

PHP Math: decbin() function

The decbin() function converts decimal number into binary. It returns binary number as a string.

Syntax

string decbin ( int $number ) 

Example

<?php  
echo (decbin(2)."<br/>");// 10  
echo (decbin(10)."<br/>");// 1010  
echo (decbin(22)."<br/>");// 10110  
?> 

Output:

10
1010
10110

PHP Math: dechex() function

The dechex() function converts decimal number into hexadecimal. It returns hexadecimal representation of given number as a string.

Syntax

string dechex ( int $number )  

Example

<?php  
echo (dechex(2)."<br/>");// 2  
echo (dechex(10)."<br/>");// a  
echo (dechex(22)."<br/>");// 16  
?>  

Output:

2
a
16

PHP Math: decoct() function

The decoct() function converts decimal number into octal. It returns octal representation of given number as a string.

Syntax

string decoct ( int $number )  

Example

<?php  
echo (decoct(2)."<br/>");// 2  
echo (decoct(10)."<br/>");// 12  
echo (decoct(22)."<br/>");// 26  
?>  

Output:

2
12
26

PHP Math: base_convert() function

The base_convert() function allows you to convert any base number to any base number. For example, you can convert hexadecimal number to binary, hexadecimal to octal, binary to octal, octal to hexadecimal, binary to decimal etc.

Syntax

string base_convert ( string $number , int $frombase , int $tobase )

Example

<?php  
$n1=10;  
echo (base_convert($n1,10,2)."<br/>");// 1010  
?>  

Output:1010

PHP Math: bindec() function

The bindec() function converts binary number into decimal.

Syntax

number bindec ( string $binary_string )  

Example

<?php  
echo (bindec(10)."<br/>");// 2  
echo (bindec(1010)."<br/>");// 10  
echo (bindec(1011)."<br/>");// 11  
?> 

Output:

2
10
11

Series: PHP Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
php math calculations php math library php math operators php calculations php subtract php multiply php average function php square

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.