SlideShare a Scribd company logo
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

PDF
4.2 PHP Function
PDF
Php Tutorials for Beginners
PDF
Php introduction
PPT
PHP complete reference with database concepts for beginners
4.2 PHP Function
Php Tutorials for Beginners
Php introduction
PHP complete reference with database concepts for beginners

What's hot (20)

PPTX
Php string function
PPT
PPTX
JSON: The Basics
PPTX
Constructor in java
PPTX
Css selectors
PPTX
Php.ppt
PDF
Python programming : Files
PPT
Php Presentation
PDF
jQuery for beginners
PPTX
Operators php
PPT
Java Servlets
PPT
SQLITE Android
PPTX
Arrays in Java
PDF
Arrays in python
PPTX
Arrays in Data Structure and Algorithm
PPTX
PHP FUNCTIONS
PPT
Php forms
PPTX
linked list in data structure
PPTX
SQL commands
PPTX
Event In JavaScript
Php string function
JSON: The Basics
Constructor in java
Css selectors
Php.ppt
Python programming : Files
Php Presentation
jQuery for beginners
Operators php
Java Servlets
SQLITE Android
Arrays in Java
Arrays in python
Arrays in Data Structure and Algorithm
PHP FUNCTIONS
Php forms
linked list in data structure
SQL commands
Event In JavaScript
Ad

Viewers also liked (16)

PPT
Php array
PDF
PHP Unit 4 arrays
PPTX
PHP array 1
PPSX
Php array
PDF
PHP Basic & Arrays
PPTX
Array in php
PPT
Synapseindia reviews on array php
PPT
03 Php Array String Functions
PPTX
PHP Functions & Arrays
PPT
Php Using Arrays
PPTX
Array in php
PDF
Arrays in PHP
PPT
PHP: Arrays
PDF
PHP Arrays
PPT
PPT
Class 4 - PHP Arrays
Php array
PHP Unit 4 arrays
PHP array 1
Php array
PHP Basic & Arrays
Array in php
Synapseindia reviews on array php
03 Php Array String Functions
PHP Functions & Arrays
Php Using Arrays
Array in php
Arrays in PHP
PHP: Arrays
PHP Arrays
Class 4 - PHP Arrays
Ad

Similar to Php array (20)

PPTX
Chapter 2 wbp.pptx
PPTX
Web Application Development using PHP Chapter 4
PPTX
Introduction to php 6
PPTX
Unit 2-Arrays.pptx
PDF
Array String - Web Programming
DOCX
Array andfunction
PPT
Arrays in php
PPT
PHP array 2
PPT
PHP - Introduction to PHP Arrays
PDF
4.1 PHP Arrays
PPTX
Arrays in PHP
PPTX
Array
PPTX
Arrays in php
PPTX
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
PPT
Web Technology - PHP Arrays
PPT
PHP-04-Arrays.ppt
PPT
Chapter 04 array
PPTX
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
PPT
Using arrays with PHP for forms and storing information
Chapter 2 wbp.pptx
Web Application Development using PHP Chapter 4
Introduction to php 6
Unit 2-Arrays.pptx
Array String - Web Programming
Array andfunction
Arrays in php
PHP array 2
PHP - Introduction to PHP Arrays
4.1 PHP Arrays
Arrays in PHP
Array
Arrays in php
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Web Technology - PHP Arrays
PHP-04-Arrays.ppt
Chapter 04 array
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Using arrays with PHP for forms and storing information

Recently uploaded (20)

PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
From loneliness to social connection charting
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Pre independence Education in Inndia.pdf
PDF
Insiders guide to clinical Medicine.pdf
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Module 3: Health Systems Tutorial Slides S2 2025
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
human mycosis Human fungal infections are called human mycosis..pptx
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Cell Structure & Organelles in detailed.
Cardiovascular Pharmacology for pharmacy students.pptx
From loneliness to social connection charting
Week 4 Term 3 Study Techniques revisited.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pre independence Education in Inndia.pdf
Insiders guide to clinical Medicine.pdf

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