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

What's hot (20)

JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
HTML-(workshop)7557.pptx
HTML-(workshop)7557.pptxHTML-(workshop)7557.pptx
HTML-(workshop)7557.pptx
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
jQuery
jQueryjQuery
jQuery
 
PPT on Basic HTML Tags
PPT on Basic HTML TagsPPT on Basic HTML Tags
PPT on Basic HTML Tags
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
Intro to html
Intro to htmlIntro to html
Intro to html
 
HTML Text formatting tags
HTML Text formatting tagsHTML Text formatting tags
HTML Text formatting tags
 
Javascript
JavascriptJavascript
Javascript
 
How to develop automated tests
How to develop automated testsHow to develop automated tests
How to develop automated tests
 
Dhtml ppt (2)
Dhtml ppt (2)Dhtml ppt (2)
Dhtml ppt (2)
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Php string function
Php string function Php string function
Php string function
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
CSS media types
CSS media typesCSS media types
CSS media types
 

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
 
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 ...
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
 
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

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

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.