Syntax
function fun_name(&$varname)
Example
<?php function my(&$num) { $num='welcome'; } $str="welcome"; my($str); echo $str; ?> |
Output
>
<?php function my(&$num) { $num='welcome'; } $str="welcome"; my($str); echo $str; ?> |
The ? operator is equivalent to an if statement.it os called a terary operator because it takes three parameters an expression :an expression that is evaluated to be TRUE and FALSE an expression that is evaluates if it tree and expression evaluated if the first is FALSE
Syntax?php $n=6; $b=7; $val=($num 1>b)?$n:$b; echo "The greatest value is $val"; ? |
The require_once()statement include and evaluates the specified file during of execution of the script.This is a behavior similar to the require() function with the only difference being that it code from a file has already been included.It will not be included again.
Syntax<?php $color='red'; $fruit='apple'; echo $fruit."color is".$color" ?> |
<?php $color='red'; $fruit='apple'; echo $fruit."color is".$color" ?> |
The include_once()statement include and evaluates the specified file during of execution of the script.This is a behavior similar to the include() function with the only difference being that it code from a file has already been included.It will not be included again.
Syntax<?php $color='red'; $fruit='apple'; echo $fruit."color is".$color" ?> |
<?php echo "a $color $fruit" // include 'vars.php include_once'vars.php' echo "a $color $fruit" ?> |
<?php $color='red'; $fruit='apple'; echo $fruit."color is".$color" ?> |
<?php echo "welcome to india": print "welcome to india"; ?> |
<?php $today=getdate(date("U")); print("$today[weekday],today[month]],today[mday],today[year]"); ?> |
list() function is used to assign values to a list of variable in one operation
syntax<?php $sum=array("india","pak"); list($a,$b)=$sum; echo "we are ,a $a,amd $b"; ?> |
ksort() function sorts an array by the keys.The values keep their original keys
syntax<?php $sum=array(a=>"india",b=>"pak"); ksort($sum); print_r($sum); ?> |
in_array() function searched an array for a specific value.This function returns TRUE if the value is found in the array or FALSE otherwise.
syntax
in_array(search,array,type)
<?php $sum=array("india","pak"); if(in_array("india",$sum) { echo"Match Found" } echo"Not found"; } ?> |
count() function counts the element of an array,of the properties or two properties of an array.
Syntax
count(array1,array2)
Example
<?php $sum=array("india","pak"); // count the elements of an array echo count($sum); ?> |
<?php $sum=array("india","pak"); array_push($arr,"usa","uk"); print_r($sum); ?> |
<?php $sum=array(0=>"apple",1=>"orange",2=>"pine apple"); asort($sum); print_r($sum); ?> |
The array_values() function returns the array containing all the values of an array
syntax<?php $sum=array(0=>"apple",1=>"orange",2=>"pine apple"); // returns the array containing all the values of an array print_r($array); ?> |
<?php $sum=array(0=>"apple",1=>"orange",2=>"apple",); echo "before using array unique"; print_r($sum); echo "after using array unique"; print_r(array_unique($sum)); ?> |
The array_sum() function returns the sum of all the values in the array
Syntax<?php // sum the all the values in the array $sum=array(0=>15,1=>15,1=>15,); echo array_sum($sum); ?> |
trim() function remove the whitespaces and other predefined character from tht both side of a string
Syntax<?php $str=" hello india"; echo "without trim".$str; // remove whitespaces from the both the string echo "with trim".trim($str); ?> |
<?php // returns the part of string echo substr("hello india",6); echo substr("hello india",6,5); ?> |
<?php // returns the position of the first occurrence of string echo strpos("hello india","io"); ?> |
<?php // returns the length the string echo strlen("hello india"); ?> |
<?php // split the string into an array print_r(str_split("hello")); print_r(str_split("hello",2)); ?> |
The strrev() function reverses the string
Syntax
strrev(string)
Example
<?php echo strrev("one line"); ?> |
<?php echo str_repeat("india",4); ?> |
<?php echo nl2br("one line .\n another line"); ?> |
<?php $str='hello india'; // it is breaks the string into an array $exp_str=explode("",$str); print_r($exp_str); // it returns the string from the elements of an array echo join("",$exp_str); ?> |
<?php $str='hello india'; // it is breaks the string into an array $exp_str=explode("",$str); print_r($exp_str); // it returns the string from the elements of an array echo implode("",$exp_str); ?> |
<?php $str="welcome to india"; echo explode("",$str); ?> |
<?php $str="hello india"; // we will split the string after each character and add a"." after each split echo chunk_split($str,1,'.'); ?> |
<?php // returns a character from the specified ASCII value echo chr(52); echo chr(052); ?> Output |
<?php $str="welcome to "; echo $str; echo "india"; echo "<br>"; //remove the whitespace from the right end of a string ech chop($str); echo "india"; ?> |
<?php $str="welcome to india"; echo $str; echo addcslashes($str,'c'); ?> |
<?php echo backcslashes("wel\come to india"); ?> |