SlideShare a Scribd company logo
1 of 27
Download to read offline
By Nikul Shah
Nikul Shah 1
Nikul Shah 2
 An array is assigned to a single variable, but it
can hold dozens of individual pieces of
information.
 Each individual bit of information, or row, is
referred to as an array element.
 Within every array element there are two parts:
the value, which contains the actual
information you want to store, and a unique
key which identifies the value.
 you will learn later how key palys an
importanat role in the process of accessing
and manipulating array elements.
Nikul Shah 3
 Keys can either be non-negative integers or
strings.
 Array with integers as key are the most
common type and known as SCALAR ARRAYs.
 Those with key as string are known as
ASSOCIATIVE ARRAY.
Nikul Shah 4
 There are 2 kinds of arrays in php: indexed
and associative arrray.
 Key of indexed array is integer starts with 0.
 Indexed array are used when we identify
things with their position.
 Associative arrays have strings as keys and
behave more like two-columns table.
 The first column is key and second is use to
access value.
Nikul Shah 5
 Numeric array
 Associative Array
 Multidimensional Array.
Nikul Shah 6
 In numeric array have to create only
elements, id will be automatically assigned to
the elements.
example
<?php
$a = array("train", "car","bus");
print_r($a);
?>
output
 Array ( [0] => train [1] => car [2] => bus )
Nikul Shah 7
 In associative array we have create element
with id.
 example
 <?php
 $a =
array("6"=>"train","7"=>"car","8"=>"bus");
 print_r($a);
 ?>
 Out put.
 Array ( [6] => train [7] => car [8] => bus )
Nikul Shah 8
 Multidimensioanl array means we have to create
array within array.
 example
 <?php
 $a = array("a","b"=>array("train","car"),"bus");
 print_r($a);
 ?>
 Out put.
 Array ( [0] => a [b] => Array ( [0] => train [1] =>
car ) [1] => bus )
Nikul Shah 9
 Create an array by using the elements from
one "keys" array and one "values" array:
 <?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");
$c=array_combine($fname,$age);
print_r($c);
?>
Nikul Shah 10
 This function is for counting the values of an
array.
 <?php
 $no=array(0=>"5",1=>"10",2=>"15",3=>"15
");
 print_r(array_count_values($no));
 ?>
Nikul Shah 11
 Compare the values of two arrays, and return the
differences(difference value is displayes of first
array.)
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger");
 $animal2=array("c"=>"dog","b"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 print_r(array_diff($animal1,$animal3));
 ?>
Nikul Shah 12
 Merge two arrays into one array:
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 print_r(array_merge($animal1,$animal2,$animal3
));
 ?>
Nikul Shah 13
 Merge two arrays into one array:
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 print_r(array_merge_recursive($animal1,$animal2
,$animal3));
 ?>
Nikul Shah 14
 Returns an array in the reverse order
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 print_r(array_reverse($animal1));
 ?>
Nikul Shah 15
 Searches an array for a given value and returns
the key
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 print_r(array_search("lion"$animal1));
 ?>
Nikul Shah 16
 The array_sum() function returns the sum of
all the values in the array.
 <?php
$a=array(5,15,25);
echo array_sum($a);
?>
Nikul Shah 17
 This function sorts an associative array in desending
order, according to the value.
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d
"=>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 arsort($animal1);
 foreach ($animal1 as $key =>$val)
 {
 echo "$key = $val"."<br>";
 }
 ?>
Nikul Shah 18
 This function sorts an associative array in ascending order,
according to the value
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"=
>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 asort($animal1);
 foreach ($animal1 as $key =>$val)
 {
 echo "$key = $val"."<br>";
 }
 ?>
Nikul Shah 19
 This function sorts an associative array in desending order,
according to the key.
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"=>"tiger
");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 arsort($animal1);
 foreach ($animal1 as $key =>$val)
 {
 echo "$key = $val"."<br>";
 }
 ?>
Nikul Shah 20
 This function sorts an associative array in ascending order,
according to the key
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"=
>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 asort($animal1);
 foreach ($animal1 as $key =>$val)
 {
 echo "$key = $val"."<br>";
 }
 ?>
Nikul Shah 21
 This function is to find out no. of elements in an
array.
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger","c"=>"d
og","d"=>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 asort($animal1);
 print_r(sizeof($animal1));
 ?>
Nikul Shah 22
 Removes the first element from an array and returns the
value of the removed element.
 <?php
 $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"=
>"tiger");
 $animal2=array("c"=>"dog","d"=>"tiger");
 $animal3=array("a"=>"cow","g"=>"tiger");
 echo array_shift($animal1);
 echo "<br>";
 print_r($animal1);

 ?>
Nikul Shah 23
 Return an array of random keys:
 <?php
 $input=array("a","b","c","d","e","f","g","h",);
 $rand_keys = array_rand($input,2);
 echo $input[$rand_keys[0]]."n";
 echo $input[$rand_keys[1]]."n";
 ?>
Nikul Shah 24
 array_push() function inserts one or more
elements to the end of an array.
 You can add one value, or as many as you
like.
 Even if your array has string keys, your added
elements will always have numeric keys.
Nikul Shah 25
 <?php
 $a=array("a"=>"tree",'b'=>"car");
 array_push($a,"bike","activa");
 print_r($a);
 ?>
Nikul Shah 26
 array_pop() function deletes the last element
of an array.
 <?php
 $a=array("tree","car","bike");
 array_pop($a);
 print_r($a);
 ?>
Nikul Shah 27

More Related Content

What's hot

Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
Avanitrambadiya
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 

What's hot (20)

Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
File handling in c
File handling in cFile handling in c
File handling in c
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 

Viewers also liked

PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
Kumar
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
mussawir20
 
Array in php
Array in phpArray in php
Array in php
ilakkiya
 

Viewers also liked (17)

Php array
Php arrayPhp array
Php array
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 
Php array
Php arrayPhp array
Php array
 
PHP Basic & Arrays
PHP Basic & ArraysPHP Basic & Arrays
PHP Basic & Arrays
 
Php
PhpPhp
Php
 
Array in php
Array in phpArray in php
Array in php
 
Synapseindia reviews on array php
Synapseindia reviews on array phpSynapseindia reviews on array php
Synapseindia reviews on array php
 
03 Php Array String Functions
03 Php Array String Functions03 Php Array String Functions
03 Php Array String Functions
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
Array in php
Array in phpArray in php
Array in php
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
PHP: Arrays
PHP: ArraysPHP: Arrays
PHP: Arrays
 
PHP Arrays
PHP ArraysPHP Arrays
PHP Arrays
 
Php ppt
Php pptPhp ppt
Php ppt
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 

Similar to Php array

Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
9780538745840 ppt ch06
9780538745840 ppt ch069780538745840 ppt ch06
9780538745840 ppt ch06
Terry Yoast
 

Similar to Php array (20)

Chapter 2 wbp.pptx
Chapter 2 wbp.pptxChapter 2 wbp.pptx
Chapter 2 wbp.pptx
 
Unit 2-Arrays.pptx
Unit 2-Arrays.pptxUnit 2-Arrays.pptx
Unit 2-Arrays.pptx
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
 
Array String - Web Programming
Array String - Web ProgrammingArray String - Web Programming
Array String - Web Programming
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
9780538745840 ppt ch06
9780538745840 ppt ch069780538745840 ppt ch06
9780538745840 ppt ch06
 
Arrays in php
Arrays in phpArrays in php
Arrays in php
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
 
Introduction to php 6
Introduction to php   6Introduction to php   6
Introduction to php 6
 
Marcs (bio)perl course
Marcs (bio)perl courseMarcs (bio)perl course
Marcs (bio)perl course
 
Array Methods.pptx
Array Methods.pptxArray Methods.pptx
Array Methods.pptx
 
4.1 PHP Arrays
4.1 PHP Arrays4.1 PHP Arrays
4.1 PHP Arrays
 
Intoduction to php arrays
Intoduction to php arraysIntoduction to php arrays
Intoduction to php arrays
 
PHP Array Functions.pptx
PHP Array Functions.pptxPHP Array Functions.pptx
PHP Array Functions.pptx
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
Laravel collections an overview - Laravel SP
Laravel collections an overview - Laravel SPLaravel collections an overview - Laravel SP
Laravel collections an overview - Laravel SP
 
JAVASCRIPT OBJECTS.pdf
JAVASCRIPT OBJECTS.pdfJAVASCRIPT OBJECTS.pdf
JAVASCRIPT OBJECTS.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 

Php array

  • 3.  An array is assigned to a single variable, but it can hold dozens of individual pieces of information.  Each individual bit of information, or row, is referred to as an array element.  Within every array element there are two parts: the value, which contains the actual information you want to store, and a unique key which identifies the value.  you will learn later how key palys an importanat role in the process of accessing and manipulating array elements. Nikul Shah 3
  • 4.  Keys can either be non-negative integers or strings.  Array with integers as key are the most common type and known as SCALAR ARRAYs.  Those with key as string are known as ASSOCIATIVE ARRAY. Nikul Shah 4
  • 5.  There are 2 kinds of arrays in php: indexed and associative arrray.  Key of indexed array is integer starts with 0.  Indexed array are used when we identify things with their position.  Associative arrays have strings as keys and behave more like two-columns table.  The first column is key and second is use to access value. Nikul Shah 5
  • 6.  Numeric array  Associative Array  Multidimensional Array. Nikul Shah 6
  • 7.  In numeric array have to create only elements, id will be automatically assigned to the elements. example <?php $a = array("train", "car","bus"); print_r($a); ?> output  Array ( [0] => train [1] => car [2] => bus ) Nikul Shah 7
  • 8.  In associative array we have create element with id.  example  <?php  $a = array("6"=>"train","7"=>"car","8"=>"bus");  print_r($a);  ?>  Out put.  Array ( [6] => train [7] => car [8] => bus ) Nikul Shah 8
  • 9.  Multidimensioanl array means we have to create array within array.  example  <?php  $a = array("a","b"=>array("train","car"),"bus");  print_r($a);  ?>  Out put.  Array ( [0] => a [b] => Array ( [0] => train [1] => car ) [1] => bus ) Nikul Shah 9
  • 10.  Create an array by using the elements from one "keys" array and one "values" array:  <?php $fname=array("Peter","Ben","Joe"); $age=array("35","37","43"); $c=array_combine($fname,$age); print_r($c); ?> Nikul Shah 10
  • 11.  This function is for counting the values of an array.  <?php  $no=array(0=>"5",1=>"10",2=>"15",3=>"15 ");  print_r(array_count_values($no));  ?> Nikul Shah 11
  • 12.  Compare the values of two arrays, and return the differences(difference value is displayes of first array.)  <?php  $animal1=array("a"=>"lion","b"=>"tiger");  $animal2=array("c"=>"dog","b"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  print_r(array_diff($animal1,$animal3));  ?> Nikul Shah 12
  • 13.  Merge two arrays into one array:  <?php  $animal1=array("a"=>"lion","b"=>"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  print_r(array_merge($animal1,$animal2,$animal3 ));  ?> Nikul Shah 13
  • 14.  Merge two arrays into one array:  <?php  $animal1=array("a"=>"lion","b"=>"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  print_r(array_merge_recursive($animal1,$animal2 ,$animal3));  ?> Nikul Shah 14
  • 15.  Returns an array in the reverse order  <?php  $animal1=array("a"=>"lion","b"=>"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  print_r(array_reverse($animal1));  ?> Nikul Shah 15
  • 16.  Searches an array for a given value and returns the key  <?php  $animal1=array("a"=>"lion","b"=>"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  print_r(array_search("lion"$animal1));  ?> Nikul Shah 16
  • 17.  The array_sum() function returns the sum of all the values in the array.  <?php $a=array(5,15,25); echo array_sum($a); ?> Nikul Shah 17
  • 18.  This function sorts an associative array in desending order, according to the value.  <?php  $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d "=>"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  arsort($animal1);  foreach ($animal1 as $key =>$val)  {  echo "$key = $val"."<br>";  }  ?> Nikul Shah 18
  • 19.  This function sorts an associative array in ascending order, according to the value  <?php  $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"= >"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  asort($animal1);  foreach ($animal1 as $key =>$val)  {  echo "$key = $val"."<br>";  }  ?> Nikul Shah 19
  • 20.  This function sorts an associative array in desending order, according to the key.  <?php  $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"=>"tiger ");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  arsort($animal1);  foreach ($animal1 as $key =>$val)  {  echo "$key = $val"."<br>";  }  ?> Nikul Shah 20
  • 21.  This function sorts an associative array in ascending order, according to the key  <?php  $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"= >"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  asort($animal1);  foreach ($animal1 as $key =>$val)  {  echo "$key = $val"."<br>";  }  ?> Nikul Shah 21
  • 22.  This function is to find out no. of elements in an array.  <?php  $animal1=array("a"=>"lion","b"=>"tiger","c"=>"d og","d"=>"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  asort($animal1);  print_r(sizeof($animal1));  ?> Nikul Shah 22
  • 23.  Removes the first element from an array and returns the value of the removed element.  <?php  $animal1=array("a"=>"lion","b"=>"tiger","c"=>"dog","d"= >"tiger");  $animal2=array("c"=>"dog","d"=>"tiger");  $animal3=array("a"=>"cow","g"=>"tiger");  echo array_shift($animal1);  echo "<br>";  print_r($animal1);   ?> Nikul Shah 23
  • 24.  Return an array of random keys:  <?php  $input=array("a","b","c","d","e","f","g","h",);  $rand_keys = array_rand($input,2);  echo $input[$rand_keys[0]]."n";  echo $input[$rand_keys[1]]."n";  ?> Nikul Shah 24
  • 25.  array_push() function inserts one or more elements to the end of an array.  You can add one value, or as many as you like.  Even if your array has string keys, your added elements will always have numeric keys. Nikul Shah 25
  • 26.  <?php  $a=array("a"=>"tree",'b'=>"car");  array_push($a,"bike","activa");  print_r($a);  ?> Nikul Shah 26
  • 27.  array_pop() function deletes the last element of an array.  <?php  $a=array("tree","car","bike");  array_pop($a);  print_r($a);  ?> Nikul Shah 27