SlideShare a Scribd company logo
1 of 21
PHP Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],PHP Array
Indexed Array PHP Array $animals =  array("dog", "cat", "fish"); echo "$animals[0]"; echo "$animals[2]"; echo "$animals"; dog fish Array
Updating and Adding Elements PHP Array $animals =  array("dog", "cat", "fish"); echo "$animals[1]";  $animals[1] = " tiger " ;   echo "$animals[1]"; $animals[] = "beaver"; echo "$animals[3]"; cat tiger beaver
Associative Array PHP Array $animals = array(  "dog“ => 15,"cat“ = >8, "fish“ => 2); echo "$animals[cat]"; $animals["bat"] = 100; echo "$animals[bat]";  8 100
Listing array element :  for PHP Array $animals = array(&quot;dog&quot;, &quot;cat&quot;, &quot;fish&quot;); for ($i = 0; $i < count($animals); $i++) { echo $i . &quot;-th animal is a $animals[$i].&quot;; } 0-th animal is a dog. 1-th animal is a cat. 2-th animal is a fish.
Listing Array Elements:  foreach PHP Array $animals = array(&quot;dog&quot;, &quot;cat&quot;, &quot;fish&quot;); foreach ($animals as $animal)  echo &quot;$animal&quot;; } dog cat fish
while  and  each PHP Array $animals = array(  &quot;dog“ => 15,&quot;cat“ => 8, &quot;fish“ => 2); while ($item = each($animals))  print &quot;weight of &quot; .  $item[&quot;key&quot;] . &quot; is &quot; . $item[&quot;value&quot;] . “.&quot;; weight of dog is 15. weight of cat is 8. weight of fish is 2.
each  and  list PHP Array $animals = array(  &quot;dog“ => 15, &quot;cat“ => 8, &quot;fish“ => 2); while (list($key, $value) =  each($animals)) print &quot;weight of $key is $value.&quot;; weight of dog is 15. weight of cat is 8. weight of fish is 2.
Multi-Dimensional Heterogeneous Array PHP Array $books = array( array(&quot;title“  => “A&quot;, &quot;author“ => “X&quot;), array(&quot;title“  => “B&quot;, “ author“ => “Y&quot;, “ price“  => 25) ); print_r($books); Array ( [0] => Array ( [title]  => A [author] => X  ) [1] => Array ( [title]  => B [author] => Y [price]  => 25 ) )
Nested Loops PHP Array for ($i=0; $i < count($books); $i++) { print &quot;$i-th book is:&quot;; while ( list($key, $value) =  each($books[$i]) ) print “ $key: $value&quot;; print &quot;&quot;; } 0-th book is: title: A author: X 1-th book is: title: B author: Y price: 25
String as an Array PHP Array $myString = &quot;My chars&quot;; echo &quot;$myString&quot;;  echo &quot;$myString[1]&quot;;  My chars y
Array functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],PHP Array
count(array1) and  sizeof(array1) PHP Array Returns the size of  array  array1 . ,[object Object],[object Object],[object Object],3 3
array array_pad(array1, length, value) PHP Array Pad array to length  length  with  value . $scores =  array(1, 2); $padded =  array_pad($scores, 5, 10); print_r($padded); Array  ( [0] => 1 [1] => 2 [2] => 10 [3] => 10 [4] => 10 )
array array_reverse(array1) PHP Array Return an array with elements in reverse order. Array  ( [0] => fish [1] => cat [2] => dog ) ,[object Object],[object Object],[object Object],[object Object]
array array_slice   (array1, offset, length) PHP Array Extract a slice of  length  from  array1  starting at offset . $array1 =  array(1, 2, 3, 4, 5, 6); $subarray =  array_slice(array1, 3, 2); print_r($subarray); Array ( [0] => 4 [1] => 5 )
boolean in_array(value, array1) PHP Array Check if  value  exists in  array1 . ,[object Object],[object Object],[object Object],1 (true) (false)
void list(var1, var2, ...) PHP Array The elements of an array are copied into the list of variables  var1, var2,  . . . ,[object Object],[object Object],[object Object],dog, cat, fish
sort(array) and  rsort(array) PHP Array Sort  the elements in an array in increasing or decreasing order. ,[object Object],[object Object],[object Object],[object Object],Array ( [0] => cat [1] => dog [2] => fish  )
asort(array), arsort(array) PHP Array Sort  an array maintaining index association. ,[object Object],[object Object],[object Object],[object Object],Array ( [1] => cat [0] => dog [2] => fish  )
ksort(array), krsort(array) PHP Array Sort  array by keys. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Array ( [cat] => 8 [dog] => 15 [fish] => 12 )

More Related Content

What's hot (20)

Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Json
JsonJson
Json
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Javascript
JavascriptJavascript
Javascript
 
php basics
php basicsphp basics
php basics
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
HTML5 - Forms
HTML5 - FormsHTML5 - Forms
HTML5 - Forms
 
Php basics
Php basicsPhp basics
Php basics
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
User authentication
User authenticationUser authentication
User authentication
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Sql injection
Sql injectionSql injection
Sql injection
 
Javascript
JavascriptJavascript
Javascript
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 

Viewers also liked

PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arraysKumar
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
03 Php Array String Functions
03 Php Array String Functions03 Php Array String Functions
03 Php Array String FunctionsGeshan Manandhar
 
Synapseindia reviews on array php
Synapseindia reviews on array phpSynapseindia reviews on array php
Synapseindia reviews on array phpsaritasingh19866
 
Arrays PHP 03
Arrays PHP 03Arrays PHP 03
Arrays PHP 03Spy Seat
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperNyros Technologies
 
Array in php
Array in phpArray in php
Array in phpilakkiya
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06Hassen Poreya
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy DemoSalman Memon
 
Conheça mais o SlideShare
Conheça mais o SlideShareConheça mais o SlideShare
Conheça mais o SlideShareRafael Pinheiro
 
Aula 5 encapsulamento, associação, polimorfismo, interfaces
Aula 5   encapsulamento, associação, polimorfismo, interfacesAula 5   encapsulamento, associação, polimorfismo, interfaces
Aula 5 encapsulamento, associação, polimorfismo, interfacesRafael Pinheiro
 
How to Create an Array & types in PHP
How to Create an Array & types in PHP How to Create an Array & types in PHP
How to Create an Array & types in PHP Ajit Sinha
 

Viewers also liked (20)

PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
03 Php Array String Functions
03 Php Array String Functions03 Php Array String Functions
03 Php Array String Functions
 
Php
PhpPhp
Php
 
PHP Basic & Arrays
PHP Basic & ArraysPHP Basic & Arrays
PHP Basic & Arrays
 
Synapseindia reviews on array php
Synapseindia reviews on array phpSynapseindia reviews on array php
Synapseindia reviews on array php
 
Array in php
Array in phpArray in php
Array in php
 
My self learn -Php
My self learn -PhpMy self learn -Php
My self learn -Php
 
Arrays PHP 03
Arrays PHP 03Arrays PHP 03
Arrays PHP 03
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
Array in php
Array in phpArray in php
Array in php
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
 
Conheça mais o SlideShare
Conheça mais o SlideShareConheça mais o SlideShare
Conheça mais o SlideShare
 
Aula 5 encapsulamento, associação, polimorfismo, interfaces
Aula 5   encapsulamento, associação, polimorfismo, interfacesAula 5   encapsulamento, associação, polimorfismo, interfaces
Aula 5 encapsulamento, associação, polimorfismo, interfaces
 
How to Create an Array & types in PHP
How to Create an Array & types in PHP How to Create an Array & types in PHP
How to Create an Array & types in PHP
 
Mini Curso Wordpress
Mini Curso WordpressMini Curso Wordpress
Mini Curso Wordpress
 
POO - Aula 1 introducao
POO - Aula 1   introducaoPOO - Aula 1   introducao
POO - Aula 1 introducao
 

Similar to PHP Arrays Guide - Indexed, Associative, Multidimensional

Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Contextlichtkind
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
 
Scripting3
Scripting3Scripting3
Scripting3Nao Dara
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP ArraysAhmed Swilam
 
Marcs (bio)perl course
Marcs (bio)perl courseMarcs (bio)perl course
Marcs (bio)perl courseBITS
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2Dave Cross
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlDave Cross
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Ajay Khatri
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perltinypigdotcom
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning PerlDave Cross
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Dhivyaa C.R
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate PerlDave Cross
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsRoy Zimmer
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Featuresfivespeed5
 

Similar to PHP Arrays Guide - Indexed, Associative, Multidimensional (20)

Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Php2
Php2Php2
Php2
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Scripting3
Scripting3Scripting3
Scripting3
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
Php Basic
Php BasicPhp Basic
Php Basic
 
Marcs (bio)perl course
Marcs (bio)perl courseMarcs (bio)perl course
Marcs (bio)perl course
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate Perl
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Features
 

Recently uploaded

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Recently uploaded (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

PHP Arrays Guide - Indexed, Associative, Multidimensional

  • 1.
  • 2. Indexed Array PHP Array $animals = array(&quot;dog&quot;, &quot;cat&quot;, &quot;fish&quot;); echo &quot;$animals[0]&quot;; echo &quot;$animals[2]&quot;; echo &quot;$animals&quot;; dog fish Array
  • 3. Updating and Adding Elements PHP Array $animals = array(&quot;dog&quot;, &quot;cat&quot;, &quot;fish&quot;); echo &quot;$animals[1]&quot;; $animals[1] = &quot; tiger &quot; ; echo &quot;$animals[1]&quot;; $animals[] = &quot;beaver&quot;; echo &quot;$animals[3]&quot;; cat tiger beaver
  • 4. Associative Array PHP Array $animals = array( &quot;dog“ => 15,&quot;cat“ = >8, &quot;fish“ => 2); echo &quot;$animals[cat]&quot;; $animals[&quot;bat&quot;] = 100; echo &quot;$animals[bat]&quot;; 8 100
  • 5. Listing array element : for PHP Array $animals = array(&quot;dog&quot;, &quot;cat&quot;, &quot;fish&quot;); for ($i = 0; $i < count($animals); $i++) { echo $i . &quot;-th animal is a $animals[$i].&quot;; } 0-th animal is a dog. 1-th animal is a cat. 2-th animal is a fish.
  • 6. Listing Array Elements: foreach PHP Array $animals = array(&quot;dog&quot;, &quot;cat&quot;, &quot;fish&quot;); foreach ($animals as $animal) echo &quot;$animal&quot;; } dog cat fish
  • 7. while and each PHP Array $animals = array( &quot;dog“ => 15,&quot;cat“ => 8, &quot;fish“ => 2); while ($item = each($animals)) print &quot;weight of &quot; . $item[&quot;key&quot;] . &quot; is &quot; . $item[&quot;value&quot;] . “.&quot;; weight of dog is 15. weight of cat is 8. weight of fish is 2.
  • 8. each and list PHP Array $animals = array( &quot;dog“ => 15, &quot;cat“ => 8, &quot;fish“ => 2); while (list($key, $value) = each($animals)) print &quot;weight of $key is $value.&quot;; weight of dog is 15. weight of cat is 8. weight of fish is 2.
  • 9. Multi-Dimensional Heterogeneous Array PHP Array $books = array( array(&quot;title“ => “A&quot;, &quot;author“ => “X&quot;), array(&quot;title“ => “B&quot;, “ author“ => “Y&quot;, “ price“ => 25) ); print_r($books); Array ( [0] => Array ( [title] => A [author] => X ) [1] => Array ( [title] => B [author] => Y [price] => 25 ) )
  • 10. Nested Loops PHP Array for ($i=0; $i < count($books); $i++) { print &quot;$i-th book is:&quot;; while ( list($key, $value) = each($books[$i]) ) print “ $key: $value&quot;; print &quot;&quot;; } 0-th book is: title: A author: X 1-th book is: title: B author: Y price: 25
  • 11. String as an Array PHP Array $myString = &quot;My chars&quot;; echo &quot;$myString&quot;; echo &quot;$myString[1]&quot;; My chars y
  • 12.
  • 13.
  • 14. array array_pad(array1, length, value) PHP Array Pad array to length length with value . $scores = array(1, 2); $padded = array_pad($scores, 5, 10); print_r($padded); Array ( [0] => 1 [1] => 2 [2] => 10 [3] => 10 [4] => 10 )
  • 15.
  • 16. array array_slice (array1, offset, length) PHP Array Extract a slice of length from array1 starting at offset . $array1 = array(1, 2, 3, 4, 5, 6); $subarray = array_slice(array1, 3, 2); print_r($subarray); Array ( [0] => 4 [1] => 5 )
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.