//Basic founctions
function name() {
echo 'Waqas</br>';
}
name();
//another example
function table() {
echo 'Name:</br>Roll #:</br>';
}
table();
//functions with arguments
$n1 =3;
$n2 =4;
function add($numb1, $numb2) {
echo $numb1 + $numb2.'</br>';
}
add($n1, $n2);
//anther example
function ddy($day, $date, $year) {
echo $day.' '.$date.' '.$year.'</br>';
}
ddy('Monday', 19, 2012);
//function with return value
function add2($num1, $num2) {
$result =$num1 + $num2;
return $result;
}
function multiply($num1, $num2) {
$result = $num1 * $num2;
return $result;
}
$sum = multiply(add2(2,2), add2(2,2));
echo $sum .'</br>';
//Global Variables and Functions
$ip = $_SERVER['REMOTE_ADDR'];
function ech_ip() {
global $ip;
$line = 'Your ip is: '.$ip;
echo $line.'</br>';
}
@ech_ip();
//random function
//rand(lower limit , upper limit);
$rand = rand();
$max_limit = getrandmax();
echo $rand.' / '. $max_limit.'</br>';
//header function //out put buffer
//header('Location:'. web addr); //ob_start(); & ob_end_flush();
$redirect_page = 'https://www.google.com';
$redirect = false;
if ($redirect==true) {
header('Location: '.$redirect_page);
}
//include and require functions & include_once & require_once functions
page1 page2
<h2>My pap</h2> <?php
<?php require 'hdr.php';
require_once 'hdr.php';
?>
?>
No comments:
Post a Comment