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

PDF
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Edureka!
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PPTX
Python: Modules and Packages
Damian T. Gordon
 
PDF
Php array
Nikul Shah
 
PPSX
Php and MySQL
Tiji Thomas
 
PPTX
Introduction to data structure and algorithms
Research Scholar in Manonmaniam Sundaranar University
 
PDF
Python - gui programming (tkinter)
Learnbay Datascience
 
PDF
Functions and modules in python
Karin Lagesen
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Edureka!
 
Arrays in PHP
Vineet Kumar Saini
 
Python: Modules and Packages
Damian T. Gordon
 
Php array
Nikul Shah
 
Php and MySQL
Tiji Thomas
 
Introduction to data structure and algorithms
Research Scholar in Manonmaniam Sundaranar University
 
Python - gui programming (tkinter)
Learnbay Datascience
 
Functions and modules in python
Karin Lagesen
 

What's hot (20)

PDF
Lecture02(constants, variable & data types)
Dhaka University of Engineering & Technology(DUET)
 
PDF
Introduction to python
Yi-Fan Chu
 
PPTX
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
SubashiniRathinavel
 
PPT
Javascript
guest03a6e6
 
PPTX
Python Data Structures and Algorithms.pptx
ShreyasLawand
 
PDF
PHP file handling
wahidullah mudaser
 
PPT
structure and union
student
 
PDF
Arrays in python
moazamali28
 
PPTX
Storage class in C Language
Nitesh Kumar Pandey
 
PPTX
Introduction to Algorithm
ChristopherEsteban2
 
PDF
sparse matrix in data structure
MAHALAKSHMI P
 
PPTX
Html
Nisa Soomro
 
PPTX
Introduction to php
Taha Malampatti
 
PDF
List , tuples, dictionaries and regular expressions in python
channa basava
 
PPTX
Html frames
ManishaSheelam
 
PPTX
Data structures and algorithms
Julie Iskander
 
PDF
Java servlets
Mukesh Tekwani
 
PDF
Python sqlite3
Alexey Bovanenko
 
Lecture02(constants, variable & data types)
Dhaka University of Engineering & Technology(DUET)
 
Introduction to python
Yi-Fan Chu
 
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
SubashiniRathinavel
 
Javascript
guest03a6e6
 
Python Data Structures and Algorithms.pptx
ShreyasLawand
 
PHP file handling
wahidullah mudaser
 
structure and union
student
 
Arrays in python
moazamali28
 
Storage class in C Language
Nitesh Kumar Pandey
 
Introduction to Algorithm
ChristopherEsteban2
 
sparse matrix in data structure
MAHALAKSHMI P
 
Introduction to php
Taha Malampatti
 
List , tuples, dictionaries and regular expressions in python
channa basava
 
Html frames
ManishaSheelam
 
Data structures and algorithms
Julie Iskander
 
Java servlets
Mukesh Tekwani
 
Python sqlite3
Alexey Bovanenko
 
Ad

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
Unit 2-Arrays.pptx
mythili213835
 
PDF
4.1 PHP Arrays
Jalpesh Vasa
 
PPT
PHP - Introduction to PHP Arrays
Vibrant Technologies & Computers
 
PDF
Array String - Web Programming
Amirul Azhar
 
PDF
PHP Basic & Arrays
M.Zalmai Rahmani
 
PPTX
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
PPTX
PHP Arrays_Introduction
To Sum It Up
 
PPTX
Introduction to php 6
pctechnology
 
PPTX
Php arrays
1crazyguy
 
PPTX
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
PPTX
Arrays in php
soumyaharitha
 
PPT
Chapter 04 array
Dhani Ahmad
 
DOCX
Array andfunction
Girmachew Tilahun
 
PPTX
Array in php
ilakkiya
 
PPTX
Chap 3php array part1
monikadeshmane
 
PPTX
Arrays in PHP
davidahaskins
 
PPTX
Array
hinanshu
 
PPT
PHP and MySQL with snapshots
richambra
 
PHP array 1
Mudasir Syed
 
PHP array 2
Mudasir Syed
 
Unit 2-Arrays.pptx
mythili213835
 
4.1 PHP Arrays
Jalpesh Vasa
 
PHP - Introduction to PHP Arrays
Vibrant Technologies & Computers
 
Array String - Web Programming
Amirul Azhar
 
PHP Basic & Arrays
M.Zalmai Rahmani
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
PHP Arrays_Introduction
To Sum It Up
 
Introduction to php 6
pctechnology
 
Php arrays
1crazyguy
 
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Arrays in php
soumyaharitha
 
Chapter 04 array
Dhani Ahmad
 
Array andfunction
Girmachew Tilahun
 
Array in php
ilakkiya
 
Chap 3php array part1
monikadeshmane
 
Arrays in PHP
davidahaskins
 
Array
hinanshu
 
PHP and MySQL with snapshots
richambra
 

Recently uploaded (20)

PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
Presentation about variables and constant.pptx
kr2589474
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Exploring AI Agents in Process Industries
amoreira6
 
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 

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!!