SlideShare a Scribd company logo
PHP Arrays
ELEGANT AND EASY WAYS TO WORK WITH THEM. PART1
I wonder what arrays are all about!
Well, to begin with they are used to store data.
Just like you store data in variables E.g. $x=5;
The major difference between arrays and variables being:
Variables aren’t as flexible as arrays.
Arrays can be used to store Homogeneous(All Ints or Floats) or
Heterogeneous(Int, Float, Char) data.
Tell me more
There are 3 types of arrays in PHP
Indexed: Accessed via a particular Index.
E.g. $x[0];
Associative: Accessed via a particular key.
E.g. $x[‘name’];
Multidimensional: Contain more than one arrays of same or different types.
E.g. $x[0][1];
Indexed arrays
How do I declare and initialize them?
$country = array(“India”, “Canada”, “USA”);
That’s how you do it. Don’t use the other way. It’s time consuming!
Indexed arrays
I want some action! Show me how to view contents of the array we just
created.
Okay, here you go – This is how you access the elements.
Echo $country[1]; #Will show you Canada.
Why?
Arrays start with a ‘0’ as primary Index.
Indexed arrays - Show me more!
That was kids stuff. Show me how to print all the elements.
Hmm, you want more action huh?
Here you go –
For($anyvariable=0; $anyvariable<count($country); $anyvariable++){
Echo $country[$anyvariable];
}
Note: count function will contain the length of the array. In this case 3.
Indexed arrays - Pay back time!
Are you kidding me? “Practice makes a man perfect”
You show me more; assignment time!
a. Create an array with numbers 1 to 20 inside it.
b. Show me how you’d print every odd number between 3 and 20.
c. If that was fun, when you arrive at the 17 make it yell out “Seventeen”.
Did you make it till here already? Very good. I appreciate your time and
efforts.
End of Part1
 End of Part1.
 This document will contain links to all other documents when complete.
 Estimated completion time: December 5th 2015 or sooner.
Ad

More Related Content

Viewers also liked (17)

Milho transgênico
Milho transgênicoMilho transgênico
Milho transgênico
Aline Karolayne
 
Nuevo stemo2
Nuevo stemo2Nuevo stemo2
Nuevo stemo2
CARLOS FELIX
 
Diploma Certificate
Diploma CertificateDiploma Certificate
Diploma Certificate
Umair Khan
 
SYNERGY4
SYNERGY4SYNERGY4
SYNERGY4
Carlos Felix
 
Дерматологический кабинет
Дерматологический кабинет Дерматологический кабинет
Дерматологический кабинет
Scientific Research Institute of Children's Infections, Saint-Petersburg, Russia
 
Cautions
CautionsCautions
Cautions
marioacostam
 
Nuevo synergyo2
Nuevo synergyo2Nuevo synergyo2
Nuevo synergyo2
CARLOS FELIX
 
A Day in the Life of Digital Professional
A Day in the Life of Digital ProfessionalA Day in the Life of Digital Professional
A Day in the Life of Digital Professional
Michael Yung
 
2016 Frente 3 módulo 9b transporte seiva bruta
2016 Frente 3 módulo 9b transporte seiva bruta2016 Frente 3 módulo 9b transporte seiva bruta
2016 Frente 3 módulo 9b transporte seiva bruta
Colégio Batista de Mantena
 
Automação de Testes de Regressão - Selenium
Automação de Testes de Regressão - SeleniumAutomação de Testes de Regressão - Selenium
Automação de Testes de Regressão - Selenium
Maiele Ranzan
 
PROMOCIONES SYNERGYO2
PROMOCIONES SYNERGYO2PROMOCIONES SYNERGYO2
PROMOCIONES SYNERGYO2
SYNERGYO2 GLOBAL
 
EL VALOR RESIDUAL
EL VALOR RESIDUALEL VALOR RESIDUAL
EL VALOR RESIDUAL
Carlos Felix
 
RF Power Amplifier Tutorial (2) Class A, B and C
RF Power Amplifier Tutorial (2) Class A, B and CRF Power Amplifier Tutorial (2) Class A, B and C
RF Power Amplifier Tutorial (2) Class A, B and C
Seong-Hun Choe
 
Testes de segurança desafios e oportunidades
Testes de segurança desafios e oportunidadesTestes de segurança desafios e oportunidades
Testes de segurança desafios e oportunidades
Qualister
 
2016 Frente 1 módulo 12 Herança dos genes cromossomos sexuais
2016 Frente 1 módulo 12 Herança dos genes cromossomos sexuais2016 Frente 1 módulo 12 Herança dos genes cromossomos sexuais
2016 Frente 1 módulo 12 Herança dos genes cromossomos sexuais
Colégio Batista de Mantena
 
Nokia Strategy Presentation
Nokia Strategy PresentationNokia Strategy Presentation
Nokia Strategy Presentation
Murali Erraguntala
 

Similar to Php arrays (20)

perl 6 hands-on tutorial
perl 6 hands-on tutorialperl 6 hands-on tutorial
perl 6 hands-on tutorial
mustafa sarac
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashing
chidabdu
 
18 hashing
18 hashing18 hashing
18 hashing
deonnash
 
Ruby cheat sheet
Ruby cheat sheetRuby cheat sheet
Ruby cheat sheet
Tharcius Silva
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
Cindy Royal
 
Cwkaa 2010
Cwkaa 2010Cwkaa 2010
Cwkaa 2010
Sam Neaves
 
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae javahashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
 
Unit 2-Arrays.pptx
Unit 2-Arrays.pptxUnit 2-Arrays.pptx
Unit 2-Arrays.pptx
mythili213835
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
monikadeshmane
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
CPAP.com Introduction to Coding: Part 1
CPAP.com Introduction to Coding: Part 1CPAP.com Introduction to Coding: Part 1
CPAP.com Introduction to Coding: Part 1
johnnygoodman
 
python isn't just a snake
python isn't just a snakepython isn't just a snake
python isn't just a snake
geekinlibrariansclothing
 
MATH 10-PERMUTATION STATISTICS AND PROBABILITY
MATH 10-PERMUTATION STATISTICS AND PROBABILITYMATH 10-PERMUTATION STATISTICS AND PROBABILITY
MATH 10-PERMUTATION STATISTICS AND PROBABILITY
JoemardFrancisco1
 
MATH 10-PERMUTATION statistics and probability
MATH 10-PERMUTATION statistics and probabilityMATH 10-PERMUTATION statistics and probability
MATH 10-PERMUTATION statistics and probability
JoemardFrancisco1
 
Course set three full notes
Course set three full notesCourse set three full notes
Course set three full notes
geekinlibrariansclothing
 
Arrays Introduction.pptx
Arrays Introduction.pptxArrays Introduction.pptx
Arrays Introduction.pptx
AtheenaNugent1
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
robertbenard
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
robertbenard
 
Arrays in c++
Arrays in c++Arrays in c++
Arrays in c++
Asaye Dilbo
 
perl 6 hands-on tutorial
perl 6 hands-on tutorialperl 6 hands-on tutorial
perl 6 hands-on tutorial
mustafa sarac
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashing
chidabdu
 
18 hashing
18 hashing18 hashing
18 hashing
deonnash
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
Cindy Royal
 
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae javahashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
monikadeshmane
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
CPAP.com Introduction to Coding: Part 1
CPAP.com Introduction to Coding: Part 1CPAP.com Introduction to Coding: Part 1
CPAP.com Introduction to Coding: Part 1
johnnygoodman
 
MATH 10-PERMUTATION STATISTICS AND PROBABILITY
MATH 10-PERMUTATION STATISTICS AND PROBABILITYMATH 10-PERMUTATION STATISTICS AND PROBABILITY
MATH 10-PERMUTATION STATISTICS AND PROBABILITY
JoemardFrancisco1
 
MATH 10-PERMUTATION statistics and probability
MATH 10-PERMUTATION statistics and probabilityMATH 10-PERMUTATION statistics and probability
MATH 10-PERMUTATION statistics and probability
JoemardFrancisco1
 
Arrays Introduction.pptx
Arrays Introduction.pptxArrays Introduction.pptx
Arrays Introduction.pptx
AtheenaNugent1
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
robertbenard
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
robertbenard
 
Ad

Recently uploaded (20)

AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Ad

Php arrays

  • 1. PHP Arrays ELEGANT AND EASY WAYS TO WORK WITH THEM. PART1
  • 2. I wonder what arrays are all about! Well, to begin with they are used to store data. Just like you store data in variables E.g. $x=5; The major difference between arrays and variables being: Variables aren’t as flexible as arrays. Arrays can be used to store Homogeneous(All Ints or Floats) or Heterogeneous(Int, Float, Char) data.
  • 3. Tell me more There are 3 types of arrays in PHP Indexed: Accessed via a particular Index. E.g. $x[0]; Associative: Accessed via a particular key. E.g. $x[‘name’]; Multidimensional: Contain more than one arrays of same or different types. E.g. $x[0][1];
  • 4. Indexed arrays How do I declare and initialize them? $country = array(“India”, “Canada”, “USA”); That’s how you do it. Don’t use the other way. It’s time consuming!
  • 5. Indexed arrays I want some action! Show me how to view contents of the array we just created. Okay, here you go – This is how you access the elements. Echo $country[1]; #Will show you Canada. Why? Arrays start with a ‘0’ as primary Index.
  • 6. Indexed arrays - Show me more! That was kids stuff. Show me how to print all the elements. Hmm, you want more action huh? Here you go – For($anyvariable=0; $anyvariable<count($country); $anyvariable++){ Echo $country[$anyvariable]; } Note: count function will contain the length of the array. In this case 3.
  • 7. Indexed arrays - Pay back time! Are you kidding me? “Practice makes a man perfect” You show me more; assignment time! a. Create an array with numbers 1 to 20 inside it. b. Show me how you’d print every odd number between 3 and 20. c. If that was fun, when you arrive at the 17 make it yell out “Seventeen”. Did you make it till here already? Very good. I appreciate your time and efforts.
  • 8. End of Part1  End of Part1.  This document will contain links to all other documents when complete.  Estimated completion time: December 5th 2015 or sooner.
  翻译: