SlideShare a Scribd company logo
PHP Arrays
Web Technology
Made By:
Tarang Desai
140950107100
CSE – B
6th
Semester
Introduction to Array
• Arrays is a collection of similar type of elements, but in PHP you can
have the elements of mixed type together in single array.
• In each PHP, each element has two parts:
• Key
• Value
• The key represents the index at which the value of element can be
stored.
• The keys are positive integers that are in ascending order.
Array Creation
• There are many ways to create an array in PHP.
• The first way is to use the current array.
• $mylist=array(10,20,30,40,50);
• The second way is to assign the value directly to the array.
• $mylist[0]=10;
• An empty array can also be created using the array construct.
• $mylist=array();
• We can have mixed type of elements in the array.
• $mylist=array(“Tarang”=>”Vadodara”,”Mandar”=>7.5);
Accessing Array Elements
• Using an array subscript we can access the array element. The value
of subscript is enclosed within the square brackets.
• $Citycode[‘Vadodara’]=0265;
• $Name[0]=“Tarang”;
• Multiple values can be set to a single scalar variable using array.
• $people=array(“Tarang”,”Mandar”,”Shivang”);
• List($operator,$accountant,$manager)=$people;
• By this assignment Tarang becomes operator, Mandar becomes
accountant and Shivang becomes the manager.
Types of Array in PHP
PHP supports three types of array:
•Numeric Arrays
•Associative Arrays
•Multidimensional Arrays
Numeric Array
• A numeric array stores each element with a numeric ID key.
• There are two ways to write a numeric array.
• Automatically
• $names = array("Peter","Quagmire","Joe");
• Manually
• $names[0] = "Peter"; $names[1] = "Quagmire";
• $names[2] = "Joe";
• $name[] =”Peter”; $name[] =“Quagmire”; $name[] = “joe”;
Example
Code
Output
Associative Array
• 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.
• Example: Using array to assign age to a person.
• $ages = array(”Brent"=>42, ”Andrew"=>25, "Joshua”=>16);
• $ages[ Brent'] = 42;‟
• $ages['Joshua'] = 16;
Example
Code
Output
Multidimensional Array
• In a multidimensional array, each element in the main array can also
be an array.
• And each element in the sub-array can be an array, and so on.
• Example:
• $shopping=array(array(“Banana”,30),array(Orange,70),array(“Mango”,100));
• echo $shopping[0][0].” costs Rs. “.$shopping[0][1].”<br/>”;
• echo $shopping[1][0].” costs Rs. “.$shopping[1][1].”<br/>”;
• echo $shopping[2][0].” costs Rs. “.$shopping[2][1].”<br/>”;
Example
Code
Output
Finding the Size of an Array
• The count() function is used to find the number of elements in the
array.
• Example:
• $icecream_menu=array('Almond Punch'=>275,'Nutty Crunch'=>160,'Choco
Dip'=>290,'Oreo Cherry'=>250);
• print "There are ".count($icecream_menu) ." flavours of icecreams
available!!"
• Output
• There are 4 flavours of icecreams available!!
Web Technology - PHP Arrays

More Related Content

What's hot (20)

PPTX
Multithreading in Java
Jayant Dalvi
 
PPT
05 Creating Stored Procedures
rehaniltifat
 
PPTX
Two-dimensional array in java
Talha mahmood
 
PDF
Method overloading, recursion, passing and returning objects from method, new...
JAINAM KAPADIYA
 
PPT
Array in Java
Shehrevar Davierwala
 
PPTX
Threads in JAVA
Haldia Institute of Technology
 
PDF
Collections In Java
Binoj T E
 
PPTX
Packages in java
Kavitha713564
 
PDF
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPT
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
PPT
Data types
myrajendra
 
PPTX
Aggregate Function - Database
Shahadat153031
 
PDF
How to make APEX print through Node.js
Dimitri Gielis
 
ODP
Java Collections
parag
 
PPTX
Common language runtime clr
SanSan149
 
PPTX
Java Annotations
Serhii Kartashov
 
PPTX
Presentation on Elementary data structures
Kuber Chandra
 
PDF
Arrays in Java
Naz Abdalla
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPT
Applet life cycle
myrajendra
 
Multithreading in Java
Jayant Dalvi
 
05 Creating Stored Procedures
rehaniltifat
 
Two-dimensional array in java
Talha mahmood
 
Method overloading, recursion, passing and returning objects from method, new...
JAINAM KAPADIYA
 
Array in Java
Shehrevar Davierwala
 
Collections In Java
Binoj T E
 
Packages in java
Kavitha713564
 
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
Data types
myrajendra
 
Aggregate Function - Database
Shahadat153031
 
How to make APEX print through Node.js
Dimitri Gielis
 
Java Collections
parag
 
Common language runtime clr
SanSan149
 
Java Annotations
Serhii Kartashov
 
Presentation on Elementary data structures
Kuber Chandra
 
Arrays in Java
Naz Abdalla
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Applet life cycle
myrajendra
 

Viewers also liked (19)

PPTX
History of Web Technology
Shuvo Malakar
 
PPTX
Web technology
PCG Solution
 
PPT
Introduction To Web Technology
Arun Kumar
 
PPTX
Seminar presentation on embedded web technology
Ranol R C
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PPTX
Web technologies lesson 1
nhepner
 
PPTX
Presentation on component based software engineering(cbse)
Chandan Thakur
 
PPTX
Introduction to Web Technology
Aashish Jain
 
PDF
Introduction to JavaScript
Bryan Basham
 
PPT
Introduction to Javascript
Amit Tyagi
 
PPT
Js ppt
Rakhi Thota
 
PPTX
multimedia technologies Introduction
Mohammed Fareed
 
PPT
JavaScript - An Introduction
Manvendra Singh
 
PPT
Php Presentation
Manish Bothra
 
PPTX
telecommunication-ppt
secomps
 
PPT
Introduction to PHP
Jussi Pohjolainen
 
PPTX
Multimedia
Shivam Tuteja
 
PDF
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
History of Web Technology
Shuvo Malakar
 
Web technology
PCG Solution
 
Introduction To Web Technology
Arun Kumar
 
Seminar presentation on embedded web technology
Ranol R C
 
Introduction to JavaScript
Andres Baravalle
 
Web technologies lesson 1
nhepner
 
Presentation on component based software engineering(cbse)
Chandan Thakur
 
Introduction to Web Technology
Aashish Jain
 
Introduction to JavaScript
Bryan Basham
 
Introduction to Javascript
Amit Tyagi
 
Js ppt
Rakhi Thota
 
multimedia technologies Introduction
Mohammed Fareed
 
JavaScript - An Introduction
Manvendra Singh
 
Php Presentation
Manish Bothra
 
telecommunication-ppt
secomps
 
Introduction to PHP
Jussi Pohjolainen
 
Multimedia
Shivam Tuteja
 
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Ad

Similar to Web Technology - PHP Arrays (20)

PPTX
PHP array 1
Mudasir Syed
 
PPT
PHP array 2
Mudasir Syed
 
PPTX
2 Arrays & Strings.pptx
aarockiaabinsAPIICSE
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PDF
4.1 PHP Arrays
Jalpesh Vasa
 
PPTX
Unit 2-Arrays.pptx
mythili213835
 
PDF
Array String - Web Programming
Amirul Azhar
 
PDF
Web app development_php_04
Hassen Poreya
 
PDF
SPL 10 | One Dimensional Array in C
Mohammad Imam Hossain
 
PPTX
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
PPTX
Array,Array Function,Get Method,Post Method
Jignesh Patel
 
PDF
Scripting3
Nao Dara
 
PPTX
Array in php
Ashok Kumar
 
PPTX
ARRAYS.pptx
MamataAnilgod
 
PPTX
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
PDF
JAVASCRIPT OBJECTS.pdf
cherop41618145
 
KEY
Potential Friend Finder
Richard Schneeman
 
KEY
Processing & Dataviz
blprnt
 
PPTX
Java 103 intro to java data structures
agorolabs
 
DOCX
Array andfunction
Girmachew Tilahun
 
PHP array 1
Mudasir Syed
 
PHP array 2
Mudasir Syed
 
2 Arrays & Strings.pptx
aarockiaabinsAPIICSE
 
Arrays in PHP
Vineet Kumar Saini
 
4.1 PHP Arrays
Jalpesh Vasa
 
Unit 2-Arrays.pptx
mythili213835
 
Array String - Web Programming
Amirul Azhar
 
Web app development_php_04
Hassen Poreya
 
SPL 10 | One Dimensional Array in C
Mohammad Imam Hossain
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Array,Array Function,Get Method,Post Method
Jignesh Patel
 
Scripting3
Nao Dara
 
Array in php
Ashok Kumar
 
ARRAYS.pptx
MamataAnilgod
 
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
JAVASCRIPT OBJECTS.pdf
cherop41618145
 
Potential Friend Finder
Richard Schneeman
 
Processing & Dataviz
blprnt
 
Java 103 intro to java data structures
agorolabs
 
Array andfunction
Girmachew Tilahun
 
Ad

Recently uploaded (20)

PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 

Web Technology - PHP Arrays

  • 1. PHP Arrays Web Technology Made By: Tarang Desai 140950107100 CSE – B 6th Semester
  • 2. Introduction to Array • Arrays is a collection of similar type of elements, but in PHP you can have the elements of mixed type together in single array. • In each PHP, each element has two parts: • Key • Value • The key represents the index at which the value of element can be stored. • The keys are positive integers that are in ascending order.
  • 3. Array Creation • There are many ways to create an array in PHP. • The first way is to use the current array. • $mylist=array(10,20,30,40,50); • The second way is to assign the value directly to the array. • $mylist[0]=10; • An empty array can also be created using the array construct. • $mylist=array(); • We can have mixed type of elements in the array. • $mylist=array(“Tarang”=>”Vadodara”,”Mandar”=>7.5);
  • 4. Accessing Array Elements • Using an array subscript we can access the array element. The value of subscript is enclosed within the square brackets. • $Citycode[‘Vadodara’]=0265; • $Name[0]=“Tarang”; • Multiple values can be set to a single scalar variable using array. • $people=array(“Tarang”,”Mandar”,”Shivang”); • List($operator,$accountant,$manager)=$people; • By this assignment Tarang becomes operator, Mandar becomes accountant and Shivang becomes the manager.
  • 5. Types of Array in PHP PHP supports three types of array: •Numeric Arrays •Associative Arrays •Multidimensional Arrays
  • 6. Numeric Array • A numeric array stores each element with a numeric ID key. • There are two ways to write a numeric array. • Automatically • $names = array("Peter","Quagmire","Joe"); • Manually • $names[0] = "Peter"; $names[1] = "Quagmire"; • $names[2] = "Joe"; • $name[] =”Peter”; $name[] =“Quagmire”; $name[] = “joe”;
  • 8. Associative Array • 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. • Example: Using array to assign age to a person. • $ages = array(”Brent"=>42, ”Andrew"=>25, "Joshua”=>16); • $ages[ Brent'] = 42;‟ • $ages['Joshua'] = 16;
  • 10. Multidimensional Array • In a multidimensional array, each element in the main array can also be an array. • And each element in the sub-array can be an array, and so on. • Example: • $shopping=array(array(“Banana”,30),array(Orange,70),array(“Mango”,100)); • echo $shopping[0][0].” costs Rs. “.$shopping[0][1].”<br/>”; • echo $shopping[1][0].” costs Rs. “.$shopping[1][1].”<br/>”; • echo $shopping[2][0].” costs Rs. “.$shopping[2][1].”<br/>”;
  • 12. Finding the Size of an Array • The count() function is used to find the number of elements in the array. • Example: • $icecream_menu=array('Almond Punch'=>275,'Nutty Crunch'=>160,'Choco Dip'=>290,'Oreo Cherry'=>250); • print "There are ".count($icecream_menu) ." flavours of icecreams available!!" • Output • There are 4 flavours of icecreams available!!