Sei sulla pagina 1di 25

*********** Data Type in Php ***********

1 when we declear a variable then first of all we have to define the data type for
that variable .
2 these data type means the type of data and it also define the size of data.

***** Types Of data type in Php *****

Mainly there Are three type of data type in php .

1 Premitive data type.


2 Derrive Data type.
3 User Define data type..

1 Premitive data type : these are those data type which are pre define . and it is
also called a basic data type like Int, float ,string etc.
2 derrived data type : these are those datatype which are derrived from help of the
permitive data type like array..
3 user define data type : these are those datatype which is desgin by user
requirement...like = Object .

note : in the case of php we cannot declear any data type using variable..we can
direct declear variable with its value.

but we find which type data in stored this variable so we can find by this method /
function

! Var_dump() : this function is used to return the type of data in variable.


example
<?php

$a = 10 ;

var_dump($a);
?>

output of this program is .

int 10

******************* Operator In Php ********************

i Operator are the speical symbols which is used to define that what particular
operation will perfomed.
ii Operator required a Operand to perfomed a task / operation .

example A + B
in the above example A , B is a Operends and Plus symbols is a Operator .

***** type Of operator In Php ********

1 unary Operator : these are those operator which is required only one operand to
performed their operations .

1 pre increment Operation ( ++ ) : In the case of this operator first the


value of is increment by one and then it is assign into the another variable .

example 1 :
<?php

$a = 10 ;
$b = ++ $a;
echo " value of a is $a ";
echo " value of b is $b ";

?>
out put of this programe is :

a = 11
b = 11

2 post increment Operation ( ++ ) : In the case of this operator first the


value of is asign to the another variable and then its increment by one .

example 1 :

<?php

$a = 10 ;
$b = $a++;
echo " value of a is $a ";
echo " value of b is $b ";

?>
out put of this programe is :

a = 11
b = 11

3 pre dencrement Operation ( -- ) : In the case of this operator first the


value of is decrement by one and then its assign into the another variable .

example 1 :

<?php

$a = 10 ;
$b = -- $a;
echo " value of a is $a ";
echo " value of b is $b ";

?>
out put of this programe is :

a = 9
b = 9

4 post dencrement Operation ( -- ) : In the case of this operator first the


value of is asign to the another variable and then its dencrement by one .

example 1 :

<?php

$a = 10 ;
$b = $a--;
echo " value of a is $a ";
echo " value of b is $b ";

?>
out put of this programe is :

a = 9
b = 10

Binary operator In Php :

binary Operator : these are those operator which is required only minimum two and
more than Two operand to performed their operations .

Type of binary Operator in Php .

1 Assigment Operator : this operator is used to assign the value to the another
variable .

Example of assignment operator :

$ a = 10 ;

In the Above Example A is a variable and 10 is the value to assign into a type
variable .

here we use Equal to operator to used Assigment one value into a variable .
$a = 10;
$b = 20;
$ans = $a + $b ;

2 Arithmatic Operator : this operator is used to performed some arithmatical


calulation in php language ..like addtion , subtratrion , multiplication etc .

there are 5 type of arithmatic operator :


1 Addtion (+)
2 Subtraction(-)
3 Multipication (*)
4 Division (/)
5 Mod ( % )

for example :

$a = 15
$b = 10;

3 Compound / shortcut Operator : this type of operator is used to perforemed some


arithmatic operation with assigment opertor :
For Example
$a = 10;

$Sum = $a + 5 ;

// in Shortcut Value

$Sum += 5
echo "$Sum";
there are five type of Shortcut operator in php

1 +=
2 -=
3 *=
4 /=
5 %=

4 Relation Operator in Php : it is also called a Conditional Operator.


2 this type of operator is used to check condition between two operands .
3 this type of operator only returen's two type of value ...
1 true value ' ( 1 )
2 False value .( 0 )

there are 7 type of relational operator in php .

1 grather than ( > )


2 Less than ( < )
3 Grather than Equal to ( >=)
4 Less than Equal to ( <=)
5 Equal to ( == )
6 Not Equal To ( !=)
7 Equal to Data type with asscii value ( ===)

Logical operator : 1 this operator is used to check multiple condtion into the
single statement's.
2 It is also called a desion making statement's.
3 in logical operator check the condition . If condition is true
then the true statements are executed. but if condition is false then false
statement is executed..
4 In Php there are three types of logical operator..
1 And ( && ) Op.
2 Or ( ||) Op.
3 Not ( ! ) Op.

And Opeartor : this Operator is check multiple condition at the single time ...
In this operator if both given condition is true than only the result is true
.. and enter to execute the true statements. but if Only one condition is false .
then its returen only False Value .
This type of Operator result Returen's only Two Value .
(i) Ture
(ii) False .

In this Operator We Are Using ( && ) This Operator in php .

now we usgin to explain this With a Truth Table of (&&)AND Operator :

Cond 1 Cond 2 Result

TRUE TRUE TRUE


FALSE TRUE FALSE
TRUE FALSE FALSE
FALSE FALSE FALSE
example 1
$a = 100;
$b = 200;
$c = 300;

var_dump( $a<$b && $a<$c); // TRUE


var_dump( $a>$b && $a>$c); // FALSE
var_dump( $a<$b && $a>$c); // FALAS
var_dump( $a>$b && $a>$c); // FALSE

Or Operator in Php : this Operator is used to check Multiple Condition into a


single line..

In this operator if any one given condition is true than only the
result is true .. and enter to execute the true statements. but if Only both
condition is false . then its returen only False Value .
This type of Operator result Returen's only Two Value .
(i) Ture
(ii) False .

In this Operator We Are Using ( || ) pipe Symbol in php .

now we usgin to explain this With a Truth Table of (||)OR Operator :

Cond 1 Cond 2 Result

TRUE TRUE TRUE


FALSE TRUE TRUE
TRUE FALSE TRUE
FALSE FALSE FALSE
Example 2

$a = 100;
$b = 200;
$c = 300;

var_dump( $a<$b || $a<$c); // TRUE


var_dump( $a>$b || $a<$c); // TRUE
var_dump( $a<$b || $a>$c); // TRUE
var_dump( $a>$b || $a>$c); // FALSE

3 Not Operator : In this Type of Operator if any condition result is given by true
then Its Convert into the False value.
and If any condition result is false then its convert into the true value.

now we usgin to explain this With a Truth Table of (!)Not Operator :

cont Result
True False
false true
example 3

$a = 500;
$b = 600;

var_dump(!$a>$b); // false.
**** Ternary Operator in Php *******

Ternary operator In Php :

Ternary Operator : these are those operator which is required only minimum three
operand to performed their operations .

It has three parts


1 Part : in this part we are define the conidtion to performed there
Operation.
2 Part : Its is called a True part : it means if the given condition is true
than this parts of statements is executed.
3 Part : its is called a False part : it means if the givin condition is
false than this parts of statement is executed.

Note : The First part is Terminated By (?) ,


second part is Terminated By colon Symbol( : )
Third part is terminated by Semi colon symbol ( ; )

Syntax to declear ternary Operator .

Condition ? [True statement ]: [ False Statement ] ;

Example

$a = 100;
$b = 200;

Var_dump($a<$b? " A is Maximum of B " : " B is Maximum of A " );

Output is
A is Maximum of B ;

******* Control Statement ******


these Are those statements which are used to control the flow of the program.
likes it deside that which statements should be execute and how many times
these statements is executed during the program execution..

Types of Control statement In Php


there are mainly three types of Control statement.

1. Branching Statements.
2. Itrative statements.
3. jump Statement.

1 Branching statements..: this statement is also called conditional statements , or


desion making statments...
because these are used to check the condition in our program.

types of branching statements.


1 if statements
2 if else statements
3 if elseif else statements
4 nested if statements.
5 switch statements...
1 If Statement : this statement is used to check single condition in our program.
in this statements if givin condition is true than statment are execute...otherwise
if block is end...

Syntax to Declear If Statement in php :

If(<Expression>) {

// statements ;
}

example :
<?php

$num = 10;

if($num>0) {
echo " this is positive nuumber ";'
}

?>
2 If - else Statements : In this type of statement check single condition in our
program. If condition is true than true statements is executed but if givin
condition is false than false statements is executed...

Syntax to declear If - else Statements in php :

If (<Expression>){

// true statements ;
}
else{

// false statements ;
}

Example :
<? php
$num = 10 ;
if($num>0){
echo "number is positive ." ;
}
else{
Echo " number is not Positive";
}
?>

3 If - elseif - else Statements : In this type of statement check Multiple


condition in our program. If givin condition is true than if block and true
statements is executed but if givin condition is false than false block and false
statements is executed....
In this type of statements check multiple choices condition in if block. and select
only one condition is true or this block of statements is executed..

syntax of if elseif else block....

if (<Expression>){

// statements ;
}
elseif(<Expression>){

// statements ;
}
elseif(<Expression>){

// statements.;

}
else{
// false statements ;
}

Example of if elseif else block..

<?php

$num= 10;

if($num>0){
echo " number is positive : ";
}
elseif($num<0){

echo " number is Negative : ";


}
else{

echo " Number is Zero " ;


}

Nested if : In this type of Statement one if block has another if block .

this type of statements is used to givin the proper output of your programe.
here nested means a next.... it means one if block have another if block and its
also else part in this if block..
in this type of statements is check multiple condition.

Syntax to Nested if :

if (<Expression>){

if (<Expression>){
// statements .
}
else{

// false statements; }
}
else{
// false statements;
}

Example :

Find out the max no ?


$a = 50;
$b = 30;
$c = 10;

if($a>$b){
if ($a > $c ){

echo " A is max no ";


}
else{
echo " A is not Greather than C ";
}
}
else{
if ($b>$c){
echo " B is max of C";
}
else{
echo " C is Max of C";
}
}

Switch Case : It is also a Descion making statement . Its is same as if -elseif


-else statements ..
it is also check multiple choices input and select one condition..

Difference between If - elseif - else OR Switch case statements.

Switch Case /// If Elseif Statements..

1 It is check Multiple choices input into a // It is also check Multiple


Condition. but is very slow spleed single condition . Speed is very fast.
accoding to switch case.. because in switch case only check
single Operator i.e equal to ( = ) Operator.
2
It is Used only On Operator is (=) It is used all type of
operator ..like Arithmatic , logical , relation..

3 Its Execution speed is very fast . it slow acoding to other statements.


4 it is Used Switch Key word... its used If - Elseif - else Keywords.

Syntax of switch case :

switch (<expression>){

Case Value 1 :
// statements ;
Break;
Case Value 2 :
// Statements;
break;
Case Value 3 :
// Statements;
break;
Default :
// false Statments ;

Example of switch case :

$num = 1;

Switch($num){

Case 1 :
echo " Monday ";
Case 2 :
echo "Tus ";
Case 3 :
Echo "Wed ";
Case 4 :
echo "Thu";
Case 5 :
echo "Fri ";
Case 6:
echo "Sat ";
Case 7 :
Echo "Sun";
Default :
Echo "Wrong Entry ";

***** LOOPs In Php ******

1Its is also called a iterative statements. or iteration and here iteration means
repetation..
2 loops is a process in which same sequence of statements will executed repetedly
untill the givin condition will not completed.

3 In php there are 3 types of loops ..


1 while loop
2 do while loop
3 for loop.

1 while Loop : It is also called a pretested loop or entry control loop.. because
in this type of loop first givin condition is checked and if given condition is
true than only statements will executed..
2 It Is Pre tested loop becoz First Condition is checked....
3 It has four parts of this loops..
i : Initialization of loop.
ii : condition of loop.
iii : statements of loop. or body part of loop.
iv : Increment or decrement of loop.

note : here all part is givin in different lines.


4 : we can used this type of loop so we can used while key word for this loop.

syntax to declear while loop.


Initialization :
while (<Condition>) {
// statements of body part of loop ;

increment / dencrement ;
}

Example :

<?php

$i = 1;
while($i<=5){

echo " hello world <br>" ;

$i++;
}

2 Do while : It is a postested loop.. here postested means . in this type of loop


first statements are executed and than condition is checked.. if in first time a
givin condition is false than a single time loop statements is execute..

2 its is post tested because after the body part of loop than condition is
checked...
3 it is only a loop thats terminated by semicolan. (;) ;

4 It has four parts of this loops..


i : Initialization of loop.
ii: statements of loop. or body part of loop.
iii : Increment or dencrement of loop.
iv : condition of loop.

note : here all part is givin in different lines.


5 : we can used this type of loop so we can used do while key word for this loop.

syntax to declear while loop.

Initialization :
do{
// statements of body part of loop ;
increment / dencrement ;
}while(<expression>);

example :

$i=1;
do{

echo "hello world";


$i++;

}while($i<=10);

3 For Loop : It is also called a pretested loop or entry cantrol loop.. because in
this type of loop first givin condition is checked and if givin condition is true
than only statements will executed..
2 It Is Pre tested loop becoz First Condtion is checked....
3 it is very popular loop because it is very easy to handle this loop .
4 It has four parts of this loops..
i : Initialization of loop.
ii : condition of loop.
iii : statements of loop. or body part of loop.
iv : Increment or dencrement of loop.
Note : The all parts of this loop is returen down into a single line i.e it is
very easy and mostlly popular.
5 : we can used this type of loop so we can used do For key word for this loop.

syntax of for loop :

(step1) (step2) (step 4)


for(<insilization> ; <test condition > ; increment / dencrement ) {

// statements ; (step3)
}
example : wap to print 1 to 10 serices of number :

<?php

for($i=1;$i<=10;$i++){

echo " No Is $i <br> ";


}

For each loop : It is very easy to handle this loop :


: this loop is basically used to print the output of the program and the
array values .:
: it is very comon to define output of the values.

syntax of foreach loop :

foreach(<array name > as <variable name >){


echo <variable name >;
}

example :

foreach($arr as $val){
echo $val;
}
11:08 PM 5/22/2019

Array : it is a derrived data type . here derrived data type means it define with
the help of primitive data type. in the case of php language its not complsary rule
:

2 : it is a collection of group of same type of data which can store into a single
variable.
3 : it define a contigious memory location.
4 : the main advantage an array is we can store multiple type of values is store
into a single variable .
Disadvantage of array is :

1 the main disadvantage is an array is we cannot store multiple type of data


into a single array .
it means we cannot store different type of data into a array value :
example : we can store all integer type of data into an array. but we cannot
store some values is integer and another values is float data type . so array is
not allow this values.

type of array In Php :

1 One/single dimensional array


2 two/multi dimensional array

note : In php A new Type type of array is also define i.e Associative Array :

1 One/ Sinlge Dimensional array :


In one dimensional array can hold many values under a single name of
variable , and you can access the values by refferring an index number .

syntax to single dimensional array :

$ <Array name > = array (<arrguments of array >);

methord 1 to define array :

$arr = array();
$arr[0] = 10;
$arr[1] = 20;
$arr[2] = 30;

echo $arr[0];
echo $arr[1];
echo $arr[2];

Associative Array : it a very speical type of array . this array is reffer to the
key value function :

it is a collection of key and value . each element can be accessed by using key
value .
note : here key can be alphanumerical , numerical and key can't be
duplicate .

3 tow thing of this type of array .


i : key
ii : value

syntax to declear associative array .

$<array name > = array ();

$<array name ['key'] = value ;

example of this array :

$arr = array();
$arr['ajay']=20;
$arr['vijay']=30;
$arr['sanjay']=25;
$arr[0]=10;
$arr[]=20;
$arr[4]=50;
$arr[]=60;

echo "$arr['ajay'];

2 Two Dimension array : in this type of array also contain another array as a value
. in such way we can create multi - dimensional array ;
in this type of array has two parts 1 row 2 column

1 it is a collection of rows & coloumn ;


2 each element be accessed by its row and coloumn index number .

syntax to declear 2d array

<$<array name > = array ();


<$<arrayname>[row-index][col-index] = value;

example of 2D array :
$arr = array();

$arr[0][0] = 10;
$arr[0][1] = 20;
$arr[0][2] = 30;
$arr[1][0] = 40;
$arr[1][1] = 50;
$arr[1][2] = 60;
$arr[2][0] = 70;
$arr[2][1] = 80;
$arr[2][2] = 90;

print_r($arr);

Q wap to one dimnemsion array into two dimnesional array ;

$arr1 = [10,20,30];
$arr2 = [40,50,60];
$arr3 = [70,80,90];

$marks = array($arr1,$arr2,$arrf3);

print_r($marks);

******************* Function in php ****************

1 A function is a block of code/statements which is used to performed a well degine


task .
2 a function is a block of code that can be used repeatedly in a program.
3 It is a concept of Reusability .
4 it means once we can create it then we can use it multiple time according to
requirements.
5 A function will not execute immediately when a page loads.
6 Function may returen a Value .
7 function can returen only one value at a time using returen keyword.
8 function keyword is used to define a function.
9 we can pass variable to function by value or by reference.
10. function name is not case sensitive in php.

syntax :

<fucntion> <Functionname>(<Arrgument list / variable list){

// code / statements..
}

for example

fucntion Sum(){

$a=10;
$b=20;
$ans = $a+$b;
echo "$ans";
}
there are two type of function in php :

1 user Define Function :


2 Library Function :

1 user define function : this function is created by user requirements .

2 every function returen a value from a function .


3 there are 4 methord to created a user define function .

i No accept argument and no return value


ii accept argument and no return value .
iii no accept argument but return value .
iv aceept argument and return value ..

1 No accept argument and no return value :

syntax :

<function> [function name] () {

// code part ;
}

calling function :

<function name>();
example 01

<?php
function Sum(){

$a=10;
$b=20;
$sum = $a+$b;
echo "$ans";
}

sum();

?>

2 Accept Argument and no return value :


1 function show($name){

echo $name;
}

show("Ajmer<br>");

sum(10,20);
2 function sum($a,$b){

echo $a."<br>";
echo $b."<br>";
$ans = $a+$b;
echo "ans is : ".$ans;

3 No Accept Argument and return value :

function basic(){

$b = 25000;
return $b;

function Da(){

$d = 2700;
return $d;
}

$bs = basic();
$d = da();
$net = $bs + $d;
echo "your net salary is : ".$net;

note : a return key word is used to return value from function :

function example(){
echo "1 edueureka academy<br>";
echo "2 edueureka academy<br>";
echo "3 edueureka academy<br>";

echo "4 edueureka academy<br>";


return;
echo "5 edueureka academy<br>";

echo "6 edueureka academy<br>";

example();

note: a return keyword is also used to terminate a function :

4 accept argument and return value ..

function basicsal($bs,$da){

$ans = $bs + $da ;


return $ans;

$net = basicsal(6000,700);
echo "ram basic salary is :".$net."<br>";

$net2 = basicsal(7000,800);
echo "shyam basic salary is :".$net2."<br>";

$net3 = basicsal(8000,900);
echo "mohan basic salary is :".$net3."<br>";

?>

Here two tech. of Calling Function :

1 call by value :
2 Call by reference :

1 Call by value : in this type of calling function the actual arrgument pass the
copy to the function .
2 it means if any changes to the function with givin arrgument that only apply in
function block : there are no change the actual arrgument value :
example of call by value :

function Changevalue($a){

$a = $a + 10;
echo "the function value of a is : ".$a;

}
$num = 10;
echo "the main value of a is : " .$num;

2 call by reference : in this type of calling funtion the actual arrgument pass the
address or reference to the function .
it means if any changes to the function with givin arrgument that apply the changes
into main arrgument value .

Note : here a address of Operator " ( & ) " is used to call by reference

example of call by reference :

function changevalue(&$a){

$a = $a +10;
echo "In funcion a value is : ".$a."<br>";

$a = 10;
echo "Before calling function a value is : ".$a."<br>";

changevalue($a);

echo "After calling function a value is : ".$a;

********** Library Function ***********

1 it is also called a pre define function .


2 this function is directly call by user and it performed there own task .
3 this function is givin by the php language for user help.
4 for example we are found a string lengh of any text so php provided a predefine
function ie. "Strlen(<string>)" ;
this function is returen the lenght of the givin string .

here some predefine function in php ..

1 <<< Heredoc operator : this type of predefine function or Operator is used


to Print multiple line of string value in php . it means you have multiple line of
string / or you have a print full pragraph in php so here <<< heredoc operator is
used :

syntax :

<<< [Variable name]

<variable name>

for example :
$msg=<<<a
hello All ' we lcome' to "Edueureka Academy " ,
adarsh nagar
ajmer,
pin:305001

a;
echo $msg;

2 strlen(<string): this function is used to find out the length of givin string :
this function always retuen a numeric value or integer value :
it return the total length of givin value of string .

syntax to strlen() function :

Strlen(<String>)

example

<?php

$msg = " Edu Eureka Academy ";


echo strlen($msg);

?>
2 substr() : the fullform of this function is sub string .
it return a number of charator from string ;
it means if we found a sub string from a givin so we can used this funtion.

syntax of substr()

substr(<string>,Start_From[numberofpostion],Counting[number])

example :

$msg = "This is Example";


echo "substr($msg,6);
3 strtoupper(): this function is used to convert a string into a upper case :

Syntax :
Strtoupper(<String>)

example :

$msg="hello india";
echo strtoupper($msg); // HELLO INDIA

3 strtolower(): this function is used to convert a string into a lower case :

Syntax :
Strtolower(<String>) //

example :

$msg="HELLO INDIA";
echo strtolower($msg); // hello india
4 ucfirst() : this function is used to convert first letter in upper case :
it means first word first letter is capital :

syntax :
ucfirst(<string>)

example

$msg = "hello world";


echo ucfirst($msg);

5ucwords(): this function is used to convert all first letter of each word is
capital letter :

syntax :
ucwords(<string>)
example :

$msg = "hello ajmer , hello india ";


ucwords($msg);
6 strrev() : this function is used to print the reverse order to the givin string :

syntax:
strrev(<string>);

example :

$msg = " hello World " ; // output is dlroW olleh


echo strrev($msg);

7 str_repeat() : this function is used to return the repeated value to the givin
string :
this function has pass two arrgument , 1 is String value , 2 is no to
repeation of string :

syntax :
echo str_repeat(<string> , 5 )

example :

$msg = " Edu uereka Academy ";


echo str_repeat($msg,5);
8 str_replace() : this function is used to replace the givin string into a another
string :
this function has three arrguments :

1 Character to be replace
2 new Character
3 string value :

syntax :

str_replace(<Charactertobereplace>,<newCharacter>,string)

example :

$msg = "hello Ajmer ";


echo str_replace("hello","hiiii",$msg);
9 ltrim() : this function is used to remove left side space to the givin string :

syntax :
ltrim(<string>);

example :
$msg = " Hello";
echo "abc".ltrim($msg);

10 rtrim() : this function is used to remove right side space to the givin
string :

syntax :
rtrim(<string>);

example :
$msg = "Hello ";
echo ltrim($msg)."abc";

11 trim() : this function is used to remove all extra splace to the givin string :

syntax:

trim();

example :

$msg = " hello Ajmer ";


echo "abc".trim($msg)."xyz";

********** Array Function ******************

1 implode() : this function is used to convert an array into the string value :
this function has passed two arrgument :
1 : Saperator
2 : array
syntax :

implode(<Saperator>,<array> )

example :

$arr = array(3,4,5,6,7,8);

var_dump($arr);

Echo $arr;
$result = implode(",", $arr);

echo "$result";

2 explode() : this function is used to convert an string into an array :


this function has passed two arrgument :
1 : Saperator
2 : string
syntax :
explode(<Saperator>,<string> )

example :

$msg = "ajmer,jaipur,kota,bundi,90";
echo $msg ;

$city = explode(",",$msg);

echo $city ; /// here there is a problem bcoz array is not directly printed .

print_r($city) ;

// or

Foreach($city as $value){

echo $value."<br>";
}
3 Count : this function is used to return the lenght of the givin array :

syntax:
count(<arrayname>)

example :
echo "the length of array is : ".count($city);

4 Sort() : this funcation is used to sort your array in assending order : A to Z

syntax :

sort(<array>);

example :

$marks = array (9,14,15,2,3,1,65,89);


$name = array("ram","shyam","mohan","sohan","seeta","geeta");

sort($marks);
foreach($marks as $value){

echo $value."<br>";
}

sort($name);

foreach($name as $val){

echo $val."<br>";
}

5rsort() : this funcation is used to sort your array in desending order : Z to A

syntax :

rsort(<array>);

example :
$marks = array (9,14,15,2,3,1,65,89);
$name = array("ram","shyam","mohan","sohan","seeta","geeta");

rsort($marks);
foreach($marks as $value){

echo $value."<br>";
}

rsort($name);

foreach($name as $val){

echo $val."<br>";
}

6 asort() : this function is used to sort assoicative array in ascending order in


php :
syntax :

asort(<array>);

example :

$age = array("ram"=>35,"shyam"=>40,"mohan"=>50,"AAA"=>12,"zzz"=>20);
asort($age);

foreach($age as $key=>$value){

echo "$key"."=".$val."<br>";
}
7 arsort() : this function is used to sort assoicative array in descending order in
php :
syntax :

arsort(<array>);

example :

$age = array("ram"=>35,"shyam"=>40,"mohan"=>50,"AAA"=>12,"zzz"=>20);
arsort($age);

foreach($age as $key=>$value){

echo "$key"."=".$val."<br>";
}

8 ksort() : this function is used to sort associative array according to the key in
ascending order in php :

syntax :
ksort(<array>);
example :

$age = array("ram"=>35,"shyam"=>40,"mohan"=>50,"AAA"=>12,"zzz"=>20);
ksort($age);
foreach($age as $key=>$value){

echo "$key"."=".$value."<br>";
}
9 krsort() : this function is used to sort associative array according to the key
in descending order in php :
syntax :
krsort(<array>);

example :
$age = array("ram"=>35,"shyam"=>40,"mohan"=>50,"AAA"=>12,"zzz"=>20);
krsort($age);

foreach($age as $key=>$value){

echo "$key"."=".$value."<br>";
}

10 is_array () : this function is used to check the givin is an array yes or no .


it means the givin arrgument is return boolean value : this boolean has two type :
first is if the boolean value is return true ie . the givin array is an array >
but if second boolean value is false ie the givin arrrgument is not an array :

syntax :
is_array(<Arrgument >) ;

example :

$a = 10 ;
$arr = array(10,20,40);

echo is_array($a)?'yes it is an array':'not is an array'; // ans is : not


is an array ;
echo is_array($arr)?'yes it is an array':'not is an array'; // yes it is an
array ;

Potrebbero piacerti anche