SlideShare una empresa de Scribd logo
1 de 12
ARRAY IN PHP Department of CE/IT
Array An array stores multiple values in one single variable. ..contains value set each element has a value, data stored in the element. And has a key by which the element can be referred to. Department of CE/IT
Department of CE/IT
What is an Array? A variable is a storage area holding a number or text. The problem is, a variable will hold only one value. An array is a special variable, which can store multiple values in one single variable. Department of CE/IT
Types of Arrays In PHP, there are three kind of arrays: Numeric array - An array with a numeric index Associative array - An array where each ID key is associated with a value Multidimensional array - An array containing one or more arrays Department of CE/IT
Initializing Arrays No of ways to initialize the array. For e.g. $ncststu[] = “Sri”; 	$ncststu[] = “Raja”; 	$ncststu[] = “Lakshmi”; $ncststu[123] = “Sri”; 	$ncststu122] = “Raja”; 	$ncststu[121] = “Lakshmi”; $ncststu = array (“Sri”, “Raja”, “Lakshmi”); to change the indices of the array use => operator. Department of CE/IT
Creating an array There are more ways to create an array in PHP. Maybe the most easiest way to create our color list array is the following: other sollution is to initialise array elements one-by-one as follows: Department of CE/IT $colorList = array("red","green","blue","black","white"); $colorList[0] = "red"; $colorList[1] = "green"; $colorList[2] = "blue"; $colorList[3] = "black"; $colorList[4] = "white";
Display the array content If you want only display one element of the array then you can just write the following code: This code will display the text "red". However you may want to display all elements in the array. You can write a loop and display them like this: Department of CE/IT echo $colorList[0]; for ($i=0;$i<=4;$i++){ echo $colorList[$i]; }
Associative Arrays An associative array, each ID key is associated with a value. When storing data about specific named values, a numerical array is not always the best way to do it. With associative arrays we can use the values as keys and assign values to them. Department of CE/IT
Example In this example we use an array to assign ages to the different persons:       $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);  Department of CE/IT
Finding the Size of an Array: To find the size of an array, use the function count().count() takes one argument, which is the array, and returns an integer represents the number of the elements of this array. Department of CE/IT
The End. Department of CE/IT

Más contenido relacionado

La actualidad más candente

La actualidad más candente (19)

Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
 
Array in php
Array in phpArray in php
Array in php
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
Introduction to php 6
Introduction to php   6Introduction to php   6
Introduction to php 6
 
Data structure in perl
Data structure in perlData structure in perl
Data structure in perl
 
Array
ArrayArray
Array
 
PHP Basic & Arrays
PHP Basic & ArraysPHP Basic & Arrays
PHP Basic & Arrays
 
Marcs (bio)perl course
Marcs (bio)perl courseMarcs (bio)perl course
Marcs (bio)perl course
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Introduction to perl_control structures
Introduction to perl_control structuresIntroduction to perl_control structures
Introduction to perl_control structures
 
Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
 
Perl
PerlPerl
Perl
 
Array String - Web Programming
Array String - Web ProgrammingArray String - Web Programming
Array String - Web Programming
 
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
 
PHP array 2
PHP array 2PHP array 2
PHP array 2
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
Scripting3
Scripting3Scripting3
Scripting3
 

Similar a Array in php

Data structures and algorithms arrays
Data structures and algorithms   arraysData structures and algorithms   arrays
Data structures and algorithms arrayschauhankapil
 
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
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: ArraysNicole Ryan
 
Data structure array
Data structure  arrayData structure  array
Data structure arrayMajidHamidAli
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptxSajalFayyaz
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.pptAqeelAbbas94
 
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesswathirajstar
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Appili Vamsi Krishna
 

Similar a Array in php (20)

Unit 2-Arrays.pptx
Unit 2-Arrays.pptxUnit 2-Arrays.pptx
Unit 2-Arrays.pptx
 
Data structures and algorithms arrays
Data structures and algorithms   arraysData structures and algorithms   arrays
Data structures and algorithms arrays
 
Chapter 2 wbp.pptx
Chapter 2 wbp.pptxChapter 2 wbp.pptx
Chapter 2 wbp.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
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
02 arrays
02 arrays02 arrays
02 arrays
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
Programming Logic and Design: Arrays
Programming Logic and Design: ArraysProgramming Logic and Design: Arrays
Programming Logic and Design: Arrays
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
 
Arrays
ArraysArrays
Arrays
 
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
 
Arrays
ArraysArrays
Arrays
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 

Más de ilakkiya

History object
History objectHistory object
History objectilakkiya
 
Twisted pair cable
Twisted pair cableTwisted pair cable
Twisted pair cableilakkiya
 
Network topology
Network topologyNetwork topology
Network topologyilakkiya
 
Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.netilakkiya
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 
Conditional statement
Conditional statementConditional statement
Conditional statementilakkiya
 
Data types in php
Data types in phpData types in php
Data types in phpilakkiya
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.netilakkiya
 
Addressing mode
Addressing modeAddressing mode
Addressing modeilakkiya
 

Más de ilakkiya (10)

History object
History objectHistory object
History object
 
Twisted pair cable
Twisted pair cableTwisted pair cable
Twisted pair cable
 
Infrared
InfraredInfrared
Infrared
 
Network topology
Network topologyNetwork topology
Network topology
 
Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.net
 
Looping statement
Looping statementLooping statement
Looping statement
 
Conditional statement
Conditional statementConditional statement
Conditional statement
 
Data types in php
Data types in phpData types in php
Data types in php
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.net
 
Addressing mode
Addressing modeAddressing mode
Addressing mode
 

Último

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Último (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

Array in php

  • 1. ARRAY IN PHP Department of CE/IT
  • 2. Array An array stores multiple values in one single variable. ..contains value set each element has a value, data stored in the element. And has a key by which the element can be referred to. Department of CE/IT
  • 4. What is an Array? A variable is a storage area holding a number or text. The problem is, a variable will hold only one value. An array is a special variable, which can store multiple values in one single variable. Department of CE/IT
  • 5. Types of Arrays In PHP, there are three kind of arrays: Numeric array - An array with a numeric index Associative array - An array where each ID key is associated with a value Multidimensional array - An array containing one or more arrays Department of CE/IT
  • 6. Initializing Arrays No of ways to initialize the array. For e.g. $ncststu[] = “Sri”; $ncststu[] = “Raja”; $ncststu[] = “Lakshmi”; $ncststu[123] = “Sri”; $ncststu122] = “Raja”; $ncststu[121] = “Lakshmi”; $ncststu = array (“Sri”, “Raja”, “Lakshmi”); to change the indices of the array use => operator. Department of CE/IT
  • 7. Creating an array There are more ways to create an array in PHP. Maybe the most easiest way to create our color list array is the following: other sollution is to initialise array elements one-by-one as follows: Department of CE/IT $colorList = array("red","green","blue","black","white"); $colorList[0] = "red"; $colorList[1] = "green"; $colorList[2] = "blue"; $colorList[3] = "black"; $colorList[4] = "white";
  • 8. Display the array content If you want only display one element of the array then you can just write the following code: This code will display the text "red". However you may want to display all elements in the array. You can write a loop and display them like this: Department of CE/IT echo $colorList[0]; for ($i=0;$i<=4;$i++){ echo $colorList[$i]; }
  • 9. Associative Arrays An associative array, each ID key is associated with a value. When storing data about specific named values, a numerical array is not always the best way to do it. With associative arrays we can use the values as keys and assign values to them. Department of CE/IT
  • 10. Example In this example we use an array to assign ages to the different persons: $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); Department of CE/IT
  • 11. Finding the Size of an Array: To find the size of an array, use the function count().count() takes one argument, which is the array, and returns an integer represents the number of the elements of this array. Department of CE/IT