SlideShare a Scribd company logo
1 of 15
Array
Array allow you to store groups of related data
in one variable.
For example, if you have a list of items, which
are to be stored in single variables, looks like:
$Company1=“Reliance”;
$Company2= “Tata”;
$Company3= “Birla”;
Each element in the array has its own index so
that it can be easily accessed.
There are three kinds of arrays in PHP:
• Numeric array
• Associative array
• Multidimensional array
Numeric Array
Numeric array can store numbers, strings and
any object but their index will be represented by
numbers.
By default array index starts from 0.
Example:
There are two methods of creating a numeric
array
$Companies=array(“Reliance”,“Tata”, “Bajaj”,
“Birla”);
or
$companies[0]=“Reliance”;
$companies[1]=“Tata”;
$companies[2]=“Bajaj”;
$companies[3]=“Birla";
echo $companies[0]. “and” .$companies[1].
“are India’s biggest corporate groups.”;
Associative Arrays
Associative arrays are very similar to numeric
arrays in term of functionality but they are
different in terms of their index.
Associative array will have their index as string
so that you can establish a strong association
between key and values.
Example
$salaries = array( “john" => 2000, “qadir" =>
1000, "zara" => 500 );
echo “salary of john is”. $salaries[‘john’];
echo “salary of qadir is”. $salaries[‘qadir’];
echo “salary of zara is”. $salaries[‘zara’];
$salaries[‘john'] = 2000;
$salaries['qadir'] = 1000;
$salaries['zara'] = 500;
echo “salary of john is”. $salaries[‘john’];
echo “salary of qadir is”. $salaries[‘qadir’];
echo “salary of zara is”. $salaries[‘zara’];
Multidimensional Array
Multidimensional arrays allow you to put an
array inside another array.
Values in the multi-dimensional array are
accessed using multiple index.
Example:
$marks = array(
“john" => array
(
"physics" => 35,
"maths" => 30,
"chemistry" => 39
),
"zara" => array
(
"physics" => 31,
"maths" => 22,
"chemistry" => 39
) );
echo "Marks for john in physics:” . $marks ['john']['physics'] ;
echo "Marks for zara in maths:” . $marks ['zara']['maths'] ;
Example:
$array1 = array(“first_name” => “kevin”,
“last_name” => “sweet”);
echo $array1[“first_name”]. “ ” .
$array1[“last_name”];
$array1[“first_name”] = “larry”;
echo $array1[“first_name”]. “ ” .
$array1[“last_name”];
Array Functions
$array1 = array(4,34,87,54,12);
print_r($array1);
Output:
Array ( [0] => 4 [1] => 34 [2] => 87 [3] => 54 [4] => 12 )
<pre> print_r($array1); </pre>
Output:
Array
(
[0] => 4
[1] => 34
[2] => 87
[3] => 54
[4] => 12
)
count the values :
echo count($array1);
Max value
echo max($array1);
Min value
echo min($array1);
Sum of elements
echo array_sum($array1);
Sort:
sort($array1); print_r($array1);
Reverse Sort:
rsort($array1); print_r($array1);
In Array:
in_array(13, $array1);
Foreach loop
foreach($array as $value)
{
statement;
}
Example:
$values = array(8,19,24,57);
foreach($values as $value)
{
echo “value is = “ . $value;
}
Output:
value is = 8
value is = 19
value is = 24
value is = 57
foreach ($array as $key => $value)
{
statement;
}
Example:
foreach($values as $position => $value)
{
echo $position . “:” . $value;
}
Output:
0:8
1:19
2:24
3:57
$prices = array(“abc” => 2000, “pqr” => 25,
“xyz” => 1000);
foreach($prices as $key => $price)
{
echo $key . “: $”. $price;
}
Output:
abc: $2000
pqr: $25
xyz: $1000

More Related Content

What's hot

What's hot (20)

Php array
Php arrayPhp array
Php array
 
Marcs (bio)perl course
Marcs (bio)perl courseMarcs (bio)perl course
Marcs (bio)perl course
 
Lists
ListsLists
Lists
 
Array,Array Function,Get Method,Post Method
Array,Array Function,Get Method,Post MethodArray,Array Function,Get Method,Post Method
Array,Array Function,Get Method,Post Method
 
Pa1 lists subset
Pa1 lists subsetPa1 lists subset
Pa1 lists subset
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Python
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
16 containers
16   containers16   containers
16 containers
 
Python - Lecture 3
Python - Lecture 3Python - Lecture 3
Python - Lecture 3
 
Sets
SetsSets
Sets
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
List in Python
List in PythonList in Python
List in Python
 
Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
 
Introduction to php 6
Introduction to php   6Introduction to php   6
Introduction to php 6
 
12. arrays
12. arrays12. arrays
12. arrays
 
GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
The data visualization with R:An Example- Visualizing obesity across united s...
The data visualization with R:An Example- Visualizing obesity across united s...The data visualization with R:An Example- Visualizing obesity across united s...
The data visualization with R:An Example- Visualizing obesity across united s...
 

Viewers also liked

File pendukung himpunan
File pendukung himpunanFile pendukung himpunan
File pendukung himpunanNova Amalia
 
bccon-2014 dev04 domino_apps_reaching_up&out
bccon-2014 dev04 domino_apps_reaching_up&outbccon-2014 dev04 domino_apps_reaching_up&out
bccon-2014 dev04 domino_apps_reaching_up&outICS User Group
 
bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014ICS User Group
 
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-librariesbccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-librariesICS User Group
 
bccon-2014 com02 level-up_building_next_generation_business_applications
bccon-2014 com02 level-up_building_next_generation_business_applicationsbccon-2014 com02 level-up_building_next_generation_business_applications
bccon-2014 com02 level-up_building_next_generation_business_applicationsICS User Group
 
bccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepause
bccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepausebccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepause
bccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepauseICS User Group
 
bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs
bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjsbccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs
bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjsICS User Group
 
Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...
Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...
Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...Макс Гнедов
 
Система управления грузоперевозками Smart Truck, презентация для МинТранса
Система управления грузоперевозками Smart Truck, презентация для МинТрансаСистема управления грузоперевозками Smart Truck, презентация для МинТранса
Система управления грузоперевозками Smart Truck, презентация для МинТрансаМакс Гнедов
 

Viewers also liked (20)

File pendukung himpunan
File pendukung himpunanFile pendukung himpunan
File pendukung himpunan
 
презентация Dancers 2.0
презентация Dancers 2.0презентация Dancers 2.0
презентация Dancers 2.0
 
Mysql
MysqlMysql
Mysql
 
bccon-2014 dev04 domino_apps_reaching_up&out
bccon-2014 dev04 domino_apps_reaching_up&outbccon-2014 dev04 domino_apps_reaching_up&out
bccon-2014 dev04 domino_apps_reaching_up&out
 
bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014bccon-2014 key01 ibm_collaboration_solutions_connect_2014
bccon-2014 key01 ibm_collaboration_solutions_connect_2014
 
Slide Show
Slide ShowSlide Show
Slide Show
 
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-librariesbccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
bccon-2014 dev02 xpages-coffe-from-a-friend-using-third-party-java-libraries
 
bccon-2014 com02 level-up_building_next_generation_business_applications
bccon-2014 com02 level-up_building_next_generation_business_applicationsbccon-2014 com02 level-up_building_next_generation_business_applications
bccon-2014 com02 level-up_building_next_generation_business_applications
 
Loop
LoopLoop
Loop
 
bccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepause
bccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepausebccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepause
bccon-2014 cas01 ibm-notes-upgrades-in-der-kaffeepause
 
Pixel poi 2.0
Pixel poi  2.0Pixel poi  2.0
Pixel poi 2.0
 
bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs
bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjsbccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs
bccon-2014 dev03 xpages-road_to_damascas-lotus-script-and-@formula-to-ssjs
 
Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...
Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...
Система управления грузоперевозками Smart Truck, презентация для МинТранса ве...
 
Система управления грузоперевозками Smart Truck, презентация для МинТранса
Система управления грузоперевозками Smart Truck, презентация для МинТрансаСистема управления грузоперевозками Smart Truck, презентация для МинТранса
Система управления грузоперевозками Smart Truck, презентация для МинТранса
 
Youtube
YoutubeYoutube
Youtube
 
Ppt himpunan
Ppt himpunanPpt himpunan
Ppt himpunan
 
Md masud rana_cv
Md masud rana_cvMd masud rana_cv
Md masud rana_cv
 
Farhan Baig CV
Farhan Baig CVFarhan Baig CV
Farhan Baig CV
 
Zahid CV
Zahid CVZahid CV
Zahid CV
 
Kashan
KashanKashan
Kashan
 

Similar to Array

Array String - Web Programming
Array String - Web ProgrammingArray String - Web Programming
Array String - Web ProgrammingAmirul Azhar
 
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 informationNicole Ryan
 
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.pptxvvvvvvvvvvvvvvZahouAmel1
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
arrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdfarrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdfMarlonMagtibay2
 
JAVASCRIPT OBJECTS.pdf
JAVASCRIPT OBJECTS.pdfJAVASCRIPT OBJECTS.pdf
JAVASCRIPT OBJECTS.pdfcherop41618145
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2Rajendran
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsKuntal Bhowmick
 

Similar to 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
 
Array String - Web Programming
Array String - Web ProgrammingArray String - Web Programming
Array String - Web Programming
 
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
 
arrays.pdf
arrays.pdfarrays.pdf
arrays.pdf
 
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
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
arrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdfarrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdf
 
JAVASCRIPT OBJECTS.pdf
JAVASCRIPT OBJECTS.pdfJAVASCRIPT OBJECTS.pdf
JAVASCRIPT OBJECTS.pdf
 
Algorithm and Programming (Array)
Algorithm and Programming (Array)Algorithm and Programming (Array)
Algorithm and Programming (Array)
 
Array lecture
Array lectureArray lecture
Array lecture
 
Comp102 lec 8
Comp102   lec 8Comp102   lec 8
Comp102 lec 8
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
 

Recently uploaded

Dubai Call Girls Pinky O525547819 Call Girl's In Dubai
Dubai Call Girls Pinky O525547819 Call Girl's In DubaiDubai Call Girls Pinky O525547819 Call Girl's In Dubai
Dubai Call Girls Pinky O525547819 Call Girl's In Dubaikojalkojal131
 
Indegene Limited IPO Detail - Divadhvik
Indegene Limited IPO Detail  - DivadhvikIndegene Limited IPO Detail  - Divadhvik
Indegene Limited IPO Detail - Divadhvikdhvikdiva
 
422524114-Patriarchy-Kamla-Bhasin gg.pdf
422524114-Patriarchy-Kamla-Bhasin gg.pdf422524114-Patriarchy-Kamla-Bhasin gg.pdf
422524114-Patriarchy-Kamla-Bhasin gg.pdflambardar420420
 
declarationleaders_sd_re_greens_theleft_5.pdf
declarationleaders_sd_re_greens_theleft_5.pdfdeclarationleaders_sd_re_greens_theleft_5.pdf
declarationleaders_sd_re_greens_theleft_5.pdfssuser5750e1
 
The political system of the united kingdom
The political system of the united kingdomThe political system of the united kingdom
The political system of the united kingdomlunadelior
 
10052024_First India Newspaper Jaipur.pdf
10052024_First India Newspaper Jaipur.pdf10052024_First India Newspaper Jaipur.pdf
10052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
06052024_First India Newspaper Jaipur.pdf
06052024_First India Newspaper Jaipur.pdf06052024_First India Newspaper Jaipur.pdf
06052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...
Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...
Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...tewhimanshu23
 
KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...
KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...
KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...IT Industry
 
11052024_First India Newspaper Jaipur.pdf
11052024_First India Newspaper Jaipur.pdf11052024_First India Newspaper Jaipur.pdf
11052024_First India Newspaper Jaipur.pdfFIRST INDIA
 
Job-Oriеntеd Courses That Will Boost Your Career in 2024
Job-Oriеntеd Courses That Will Boost Your Career in 2024Job-Oriеntеd Courses That Will Boost Your Career in 2024
Job-Oriеntеd Courses That Will Boost Your Career in 2024Insiger
 
Politician uddhav thackeray biography- Full Details
Politician uddhav thackeray biography- Full DetailsPolitician uddhav thackeray biography- Full Details
Politician uddhav thackeray biography- Full DetailsVoterMood
 

Recently uploaded (14)

Dubai Call Girls Pinky O525547819 Call Girl's In Dubai
Dubai Call Girls Pinky O525547819 Call Girl's In DubaiDubai Call Girls Pinky O525547819 Call Girl's In Dubai
Dubai Call Girls Pinky O525547819 Call Girl's In Dubai
 
call girls inMahavir Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls inMahavir Nagar  (delhi) call me [🔝9953056974🔝] escort service 24X7call girls inMahavir Nagar  (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls inMahavir Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Indegene Limited IPO Detail - Divadhvik
Indegene Limited IPO Detail  - DivadhvikIndegene Limited IPO Detail  - Divadhvik
Indegene Limited IPO Detail - Divadhvik
 
422524114-Patriarchy-Kamla-Bhasin gg.pdf
422524114-Patriarchy-Kamla-Bhasin gg.pdf422524114-Patriarchy-Kamla-Bhasin gg.pdf
422524114-Patriarchy-Kamla-Bhasin gg.pdf
 
declarationleaders_sd_re_greens_theleft_5.pdf
declarationleaders_sd_re_greens_theleft_5.pdfdeclarationleaders_sd_re_greens_theleft_5.pdf
declarationleaders_sd_re_greens_theleft_5.pdf
 
The political system of the united kingdom
The political system of the united kingdomThe political system of the united kingdom
The political system of the united kingdom
 
10052024_First India Newspaper Jaipur.pdf
10052024_First India Newspaper Jaipur.pdf10052024_First India Newspaper Jaipur.pdf
10052024_First India Newspaper Jaipur.pdf
 
9953056974 Call Girls In Pratap Nagar, Escorts (Delhi) NCR
9953056974 Call Girls In Pratap Nagar, Escorts (Delhi) NCR9953056974 Call Girls In Pratap Nagar, Escorts (Delhi) NCR
9953056974 Call Girls In Pratap Nagar, Escorts (Delhi) NCR
 
06052024_First India Newspaper Jaipur.pdf
06052024_First India Newspaper Jaipur.pdf06052024_First India Newspaper Jaipur.pdf
06052024_First India Newspaper Jaipur.pdf
 
Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...
Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...
Unveiling the Characteristics of Political Institutions_ A Comprehensive Anal...
 
KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...
KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...
KING VISHNU BHAGWANON KA BHAGWAN PARAMATMONKA PARATOMIC PARAMANU KASARVAMANVA...
 
11052024_First India Newspaper Jaipur.pdf
11052024_First India Newspaper Jaipur.pdf11052024_First India Newspaper Jaipur.pdf
11052024_First India Newspaper Jaipur.pdf
 
Job-Oriеntеd Courses That Will Boost Your Career in 2024
Job-Oriеntеd Courses That Will Boost Your Career in 2024Job-Oriеntеd Courses That Will Boost Your Career in 2024
Job-Oriеntеd Courses That Will Boost Your Career in 2024
 
Politician uddhav thackeray biography- Full Details
Politician uddhav thackeray biography- Full DetailsPolitician uddhav thackeray biography- Full Details
Politician uddhav thackeray biography- Full Details
 

Array

  • 1. Array Array allow you to store groups of related data in one variable. For example, if you have a list of items, which are to be stored in single variables, looks like: $Company1=“Reliance”; $Company2= “Tata”; $Company3= “Birla”;
  • 2. Each element in the array has its own index so that it can be easily accessed. There are three kinds of arrays in PHP: • Numeric array • Associative array • Multidimensional array
  • 3. Numeric Array Numeric array can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from 0. Example: There are two methods of creating a numeric array
  • 5. Associative Arrays Associative arrays are very similar to numeric arrays in term of functionality but they are different in terms of their index. Associative array will have their index as string so that you can establish a strong association between key and values.
  • 6. Example $salaries = array( “john" => 2000, “qadir" => 1000, "zara" => 500 ); echo “salary of john is”. $salaries[‘john’]; echo “salary of qadir is”. $salaries[‘qadir’]; echo “salary of zara is”. $salaries[‘zara’];
  • 7. $salaries[‘john'] = 2000; $salaries['qadir'] = 1000; $salaries['zara'] = 500; echo “salary of john is”. $salaries[‘john’]; echo “salary of qadir is”. $salaries[‘qadir’]; echo “salary of zara is”. $salaries[‘zara’];
  • 8. Multidimensional Array Multidimensional arrays allow you to put an array inside another array. Values in the multi-dimensional array are accessed using multiple index.
  • 9. Example: $marks = array( “john" => array ( "physics" => 35, "maths" => 30, "chemistry" => 39 ), "zara" => array ( "physics" => 31, "maths" => 22, "chemistry" => 39 ) ); echo "Marks for john in physics:” . $marks ['john']['physics'] ; echo "Marks for zara in maths:” . $marks ['zara']['maths'] ;
  • 10. Example: $array1 = array(“first_name” => “kevin”, “last_name” => “sweet”); echo $array1[“first_name”]. “ ” . $array1[“last_name”]; $array1[“first_name”] = “larry”; echo $array1[“first_name”]. “ ” . $array1[“last_name”];
  • 11. Array Functions $array1 = array(4,34,87,54,12); print_r($array1); Output: Array ( [0] => 4 [1] => 34 [2] => 87 [3] => 54 [4] => 12 ) <pre> print_r($array1); </pre> Output: Array ( [0] => 4 [1] => 34 [2] => 87 [3] => 54 [4] => 12 )
  • 12. count the values : echo count($array1); Max value echo max($array1); Min value echo min($array1); Sum of elements echo array_sum($array1); Sort: sort($array1); print_r($array1); Reverse Sort: rsort($array1); print_r($array1); In Array: in_array(13, $array1);
  • 13. Foreach loop foreach($array as $value) { statement; } Example: $values = array(8,19,24,57); foreach($values as $value) { echo “value is = “ . $value; } Output: value is = 8 value is = 19 value is = 24 value is = 57
  • 14. foreach ($array as $key => $value) { statement; } Example: foreach($values as $position => $value) { echo $position . “:” . $value; } Output: 0:8 1:19 2:24 3:57
  • 15. $prices = array(“abc” => 2000, “pqr” => 25, “xyz” => 1000); foreach($prices as $key => $price) { echo $key . “: $”. $price; } Output: abc: $2000 pqr: $25 xyz: $1000