SlideShare a Scribd company logo
ARRAY IN PHPDepartment of CE/IT
ArrayAn array stores multiple values in one single variable...contains value seteach 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 ArraysIn PHP, there are three kind of arrays:Numeric array - An array with a numeric indexAssociative array - An array where each ID key is associated with a valueMultidimensional array - An array containing one or more arraysDepartment of CE/IT
Initializing ArraysNo 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 arrayThere 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 contentIf 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/ITecho $colorList[0];for ($i=0;$i<=4;$i++){echo $colorList[$i];}
Associative ArraysAn 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
ExampleIn 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

More Related Content

PPT
Php array
Core Lee
 
PPTX
How to Create an Array & types in PHP
Ajit Sinha
 
PDF
Php array
Nikul Shah
 
PPT
Php Using Arrays
mussawir20
 
PPT
Arrays in PHP
Compare Infobase Limited
 
PPT
03 Php Array String Functions
Geshan Manandhar
 
PDF
4.1 PHP Arrays
Jalpesh Vasa
 
PPTX
PHP array 1
Mudasir Syed
 
Php array
Core Lee
 
How to Create an Array & types in PHP
Ajit Sinha
 
Php array
Nikul Shah
 
Php Using Arrays
mussawir20
 
03 Php Array String Functions
Geshan Manandhar
 
4.1 PHP Arrays
Jalpesh Vasa
 
PHP array 1
Mudasir Syed
 

What's hot (19)

PPTX
Chap 3php array part1
monikadeshmane
 
PPTX
Array in php
Ashok Kumar
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PPT
Class 4 - PHP Arrays
Ahmed Swilam
 
PDF
PHP Unit 4 arrays
Kumar
 
PPTX
Introduction to php 6
pctechnology
 
PPTX
Data structure in perl
sana mateen
 
PPTX
Array
hinanshu
 
PDF
PHP Basic & Arrays
M.Zalmai Rahmani
 
PPTX
Marcs (bio)perl course
BITS
 
PDF
Sorting arrays in PHP
Vineet Kumar Saini
 
PPT
Introduction to perl_control structures
Vamshi Santhapuri
 
PPTX
Array,lists and hashes in perl
sana mateen
 
PDF
Array String - Web Programming
Amirul Azhar
 
PPTX
Array,Array Function,Get Method,Post Method
Jignesh Patel
 
PPT
PHP array 2
Mudasir Syed
 
PDF
Scripting3
Nao Dara
 
Chap 3php array part1
monikadeshmane
 
Array in php
Ashok Kumar
 
Arrays in PHP
Vineet Kumar Saini
 
Class 4 - PHP Arrays
Ahmed Swilam
 
PHP Unit 4 arrays
Kumar
 
Introduction to php 6
pctechnology
 
Data structure in perl
sana mateen
 
Array
hinanshu
 
PHP Basic & Arrays
M.Zalmai Rahmani
 
Marcs (bio)perl course
BITS
 
Sorting arrays in PHP
Vineet Kumar Saini
 
Introduction to perl_control structures
Vamshi Santhapuri
 
Array,lists and hashes in perl
sana mateen
 
Array String - Web Programming
Amirul Azhar
 
Array,Array Function,Get Method,Post Method
Jignesh Patel
 
PHP array 2
Mudasir Syed
 
Scripting3
Nao Dara
 
Ad

Similar to Array in php (20)

PPT
Web Technology - PHP Arrays
Tarang Desai
 
PPTX
Unit 2-Arrays.pptx
mythili213835
 
PPTX
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
PPTX
PHP Arrays_Introduction
To Sum It Up
 
PPT
PHP-04-Arrays.ppt
Leandro660423
 
DOCX
Array andfunction
Girmachew Tilahun
 
PPT
Chapter 04 array
Dhani Ahmad
 
PPTX
Php arrays
1crazyguy
 
PPTX
Arrays in php
soumyaharitha
 
PPTX
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
PPTX
Arrays in PHP
davidahaskins
 
PPTX
Chapter 2 wbp.pptx
40NehaPagariya
 
PPT
Php course-in-navimumbai
vibrantuser
 
PDF
PHP-Part3
Ahmed Saihood
 
PPT
PHP - Introduction to PHP Arrays
Vibrant Technologies & Computers
 
PPTX
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ayushmishraaa09
 
PPSX
DIWE - Advanced PHP Concepts
Rasan Samarasinghe
 
PPTX
2. array and numerical arrays
NurAliaAqilaMuhalis
 
PPT
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
PPT
Php basics
hamfu
 
Web Technology - PHP Arrays
Tarang Desai
 
Unit 2-Arrays.pptx
mythili213835
 
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
PHP Arrays_Introduction
To Sum It Up
 
PHP-04-Arrays.ppt
Leandro660423
 
Array andfunction
Girmachew Tilahun
 
Chapter 04 array
Dhani Ahmad
 
Php arrays
1crazyguy
 
Arrays in php
soumyaharitha
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Arrays in PHP
davidahaskins
 
Chapter 2 wbp.pptx
40NehaPagariya
 
Php course-in-navimumbai
vibrantuser
 
PHP-Part3
Ahmed Saihood
 
PHP - Introduction to PHP Arrays
Vibrant Technologies & Computers
 
5 Arry in PHP.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ayushmishraaa09
 
DIWE - Advanced PHP Concepts
Rasan Samarasinghe
 
2. array and numerical arrays
NurAliaAqilaMuhalis
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
Php basics
hamfu
 
Ad

More from ilakkiya (10)

PPTX
History object
ilakkiya
 
PPTX
Twisted pair cable
ilakkiya
 
PPTX
Infrared
ilakkiya
 
PPTX
Network topology
ilakkiya
 
PPTX
Looping statement in vb.net
ilakkiya
 
PPTX
Looping statement
ilakkiya
 
PPTX
Conditional statement
ilakkiya
 
PPTX
Data types in php
ilakkiya
 
PPTX
Decision statements in vb.net
ilakkiya
 
PPTX
Addressing mode
ilakkiya
 
History object
ilakkiya
 
Twisted pair cable
ilakkiya
 
Infrared
ilakkiya
 
Network topology
ilakkiya
 
Looping statement in vb.net
ilakkiya
 
Looping statement
ilakkiya
 
Conditional statement
ilakkiya
 
Data types in php
ilakkiya
 
Decision statements in vb.net
ilakkiya
 
Addressing mode
ilakkiya
 

Recently uploaded (20)

PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PPTX
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PDF
Introducing Procurement and Supply L2M1.pdf
labyankof
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
MariellaTBesana
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
Introducing Procurement and Supply L2M1.pdf
labyankof
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
MariellaTBesana
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
Landforms and landscapes data surprise preview
jpinnuck
 
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 

Array in php

  • 2. ArrayAn array stores multiple values in one single variable...contains value seteach 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 ArraysIn PHP, there are three kind of arrays:Numeric array - An array with a numeric indexAssociative array - An array where each ID key is associated with a valueMultidimensional array - An array containing one or more arraysDepartment of CE/IT
  • 6. Initializing ArraysNo 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 arrayThere 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 contentIf 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/ITecho $colorList[0];for ($i=0;$i<=4;$i++){echo $colorList[$i];}
  • 9. Associative ArraysAn 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. ExampleIn 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