Main PDF 4 - PHP Predefined Functions
Main PDF 4 - PHP Predefined Functions
Emerging Technologies
MODULE 4
Objectives
• To know how to include separate PHP code in the main
page for code enhancement.
• To be familiar with the use of common predefined function
such as define, include, and require.
• To use different available mathematical function for
manipulating numbers.
• To use number_format() function for number readability
purpose.
• To apply different function for Array Manipulation using the
function unset(), explode(), and implode().
• To manipulate string data using PHP string manipulation
function.
• To manipulate date with format using date function and
date format available.
PHP Predefined Functions
Using Constant
define() functions
used to declare constants. A constant can only be assigned a
scalar value, like a string or a number. A constant’s value
cannot be changed.
Syntax:
define(‘NAME’,’value’);
Example: Output:
PHP Predefined Functions
Including Files
You can separate your PHP file and embed it to your html by
using PHP include functions.
Including Files
You may write the file with an extension name of .inc rather than
.php to serve as a fragment of your program code.
Example:
Output:
PHP Predefined Functions
Example:
Output:
PHP Predefined Functions
Example: header.inc
Output:
Mathematical Function:
rand() function
- used to generate random integers
- syntax
int rand(void)
int rand(int $min, int $max)
ceil() function
- returns the next highest integer by rounding the value upwards
- syntax
float ceil(float $value)
floor() function
- returns the next lowest integer by rounding the value downwards
- syntax
float floor(float $value)
PHP Predefined Functions
Mathematical Function:
min() function
- Return the smallest value
- syntax
mixed min(array $values)
mixed min(mixed $values1, mixed $values2[,mixed $...])
max() function
- Return the highest value
- syntax
mixed max(array $values)
mixed max(mixed $values1, mixed $values2[,mixed $...])
PHP Predefined Functions
Mathematical Function:
rand(), ceil(), floor(), min(), max()
Example: Output:
PHP Predefined Functions
Mathematical Function:
number_format() function
- Format a number with grouped thousand
- syntax
string number_format (
float $number
[, int $decimals = 0 ] )
string number_format (
float $number ,
int $decimals = 0 ,
string $dec_point = '.' ,
string $thousands_sep = ',' )
PHP Predefined Functions
Example: Output:
PHP Predefined Functions
Example:
Output:
PHP Predefined Functions
Example:
Output:
PHP Predefined Functions
Output:
Example:
PHP Predefined Functions
Output:
Example:
PHP Predefined Functions
http://php.net/docs.php
PHP Predefined Functions
Example:
Output:
PHP Predefined Functions