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

Html Intro2
Html Intro2Html Intro2
Html Intro2
mlackner
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
HTML5 - Forms
HTML5 - FormsHTML5 - Forms
HTML5 - Forms
tina1357
 

What's hot (20)

Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 
Dynamic HTML (DHTML)
Dynamic HTML (DHTML)Dynamic HTML (DHTML)
Dynamic HTML (DHTML)
 
Html form tag
Html form tagHtml form tag
Html form tag
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
 
Css box-model
Css box-modelCss box-model
Css box-model
 
Html Intro2
Html Intro2Html Intro2
Html Intro2
 
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
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Html Form Controls
Html Form ControlsHtml Form Controls
Html Form Controls
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
HTML5 - Forms
HTML5 - FormsHTML5 - Forms
HTML5 - Forms
 
Css
CssCss
Css
 
Files in php
Files in phpFiles in php
Files in php
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
 
Html ppt
Html pptHtml ppt
Html ppt
 
Bootstrap ppt
Bootstrap pptBootstrap ppt
Bootstrap ppt
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
 

Viewers also liked

PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
Kumar
 
Array in php
Array in phpArray in php
Array in php
ilakkiya
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06
Hassen Poreya
 

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
 
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
 
Aula 2 conversao de variaveis j option-pane
Aula 2   conversao de variaveis j option-paneAula 2   conversao de variaveis j option-pane
Aula 2 conversao de variaveis j option-pane
 

Similar to Php array

Scripting3
Scripting3Scripting3
Scripting3
Nao Dara
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
Dave Cross
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
tinypigdotcom
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Features
fivespeed5
 

Similar to Php array (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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

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...
 
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 Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Php array

  • 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.