0% found this document useful (0 votes)
6 views

php3

The document provides an overview of PHP functions, including built-in functions like is_int(), round(), and user-defined functions with examples of syntax and usage. It also covers PHP function arguments, how to return values from functions, and introduces MySQL as a database system, including its features and how to open a connection to it. The document emphasizes the ease of use and reliability of both PHP functions and MySQL.

Uploaded by

bassel.2123018
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

php3

The document provides an overview of PHP functions, including built-in functions like is_int(), round(), and user-defined functions with examples of syntax and usage. It also covers PHP function arguments, how to return values from functions, and introduces MySQL as a database system, including its features and how to open a connection to it. The document emphasizes the ease of use and reliability of both PHP functions and MySQL.

Uploaded by

bassel.2123018
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PHP

Faisal Salaheldeen
STEM Obour
PHP Functions
PHP Built-in Functions
PHP has over 1000 built-in functions that can be called
directly, to perform a specific task.
Examples of using PHP functions
is_int() check if the variable data type is integer.
is_float() to check if the type of a variable is float.
is_nan() to check if a value is not a number.
is_numeric() to find whether a variable is numeric.
pi() function returns the value of PI.
min() and max() to find the lowest or highest value in a list
of arguments.
PHP Functions
• Ex. echo(min(0, 150, 30, 20, -8, -200)); // returns -200
round() function rounds a floating-point number to its
nearest integer
Ex. echo(round(0.49)); // returns 0
rand() function generates a random number.
isset() Determine if a variable is declared and is different
than null.
unset(variables_name) to delete variable.
var_dump(variables_name) to information about a
variable.
empty — Determine whether a variable is empty.
strlen — Get string length.
PHP User Defined Functions
• Besides the built-in PHP functions, it is possible to create
your own functions.
• A function is a block of statements that can be used
repeatedly in a program.
• A function will be executed by a call to the function.

• Syntax
• function functionName() {
code to be executed;
}
PHP User Defined Functions
<?php
function writeMsg() {
echo "Hello world!";
}

writeMsg(); // call the function


?>
PHP Function Arguments
• Information can be passed to functions through arguments. An
argument is just like a variable.
• Arguments are specified after the function name, inside the
parentheses. You can add as many arguments as you want, just
separate them with a comma.
• Function can take one or more arguments.
• Example
• <?php
• function familyName($fname, $year) {
• echo "$fname Refsnes. Born in $year <br>";
• }

• familyName("Hege","1975");
• familyName("Stale","1978");
• familyName("Kai Jim","1983");
• ?>
PHP Function Arguments
• Results of previous example.
• Hege Refsnes. Born in 1975
Stale Refsnes. Born in 1978
Kai Jim Refsnes. Born in 1983
PHP Functions - Returning values
• To let a function return a value, use the return statement:
• Example
• <?php
function sum($x, $y) {
$z = $x + $y;
return $z;
}

echo "5 + 10 = " . sum(5, 10) . "<br>";


echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>
PHP Functions - Returning values
• Results
• 5 + 10 = 15
7 + 13 = 20
2+4=6
PHP MySQL Database
• What is MySQL?
• MySQL is a database system used on the web
• MySQL is a database system that runs on a server
• MySQL is ideal for both small and large applications
• MySQL is very fast, reliable, and easy to use
• MySQL uses standard SQL
• MySQL compiles on a number of platforms
• MySQL is free to download and use
• MySQL is developed, distributed, and supported by
Oracle Corporation
Open a Connection to MySQL
• <?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = mysqli_connect($servername, $username,
$password);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>

You might also like