SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
Lecturer:
M.Zalmai “Rahmani”
rahmani.zalmai@gmail.com
Web Programming II
Lecture 03
PHP Basic & Arrays
Azma Institute
Database Department
PHP Arrays
What is an Array?
 A variable is a storage area holding a number or text.The problem is, a
variable will hold only one value.
 An array is a special variable, which can store multiple values in one single
variable.
 If you have a list of items (a list of car names, for example), storing the
cars in single variables could look like this:
$cars1="Saab";
$cars2="Volvo";
$cars3="BMW";
 However, what if you want to loop through the cars and find a specific
one? And what if you had not 3 cars, but 300?
The best solution here is to use an array!
PHP Arrays
What is an Array?
 An array can hold all your variable values under a single name. And you
can access the values by referring to the array name.
 Each element in the array has its own index so that it can be easily
accessed.
 In PHP, there are three kind of arrays:
• Numeric array - An array with a numeric index
• Associative array - An array where each ID key is associated with a value
• Multidimensional array - An array containing one or more arrays
PHP Arrays
Numeric Arrays
 A numeric array stores each array element with a numeric index.
There are two methods to create a numeric array.
PHP Arrays
Example
PHP Arrays
Associative Arrays
 An associative array, each ID key is associated with a value.
 When storing data about specific named values, a numerical array is not
always the best way to do it.
 With associative arrays we can use the values as keys and assign values to
them.
PHP Arrays
Example
PHP Arrays
Example
PHP Arrays
Multidimensional Arrays is Not Recommend in this Course
We will study in next semester
PHP Arrays
Multidimensional Arrays
 In a multidimensional array, each element in the main array can also be an
array. And each element in the sub-array can be an array, and so on.
PHP Arrays
www.w3schools.com
PHP Basic & Arrays

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Types of Arrays
Types of ArraysTypes of Arrays
Types of Arrays
 
2. array and numerical arrays
2. array and numerical arrays2. array and numerical arrays
2. array and numerical arrays
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Php array
Php arrayPhp array
Php array
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
Php array
Php arrayPhp array
Php array
 
PPt. on An _Array in C
PPt. on An _Array in CPPt. on An _Array in C
PPt. on An _Array in C
 
Array1
Array1Array1
Array1
 
Php arrays
Php arraysPhp arrays
Php arrays
 
Data structures
Data structures Data structures
Data structures
 
Array in c
Array in cArray in c
Array in c
 
Arrays Java
Arrays JavaArrays Java
Arrays Java
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
12. arrays
12. arrays12. arrays
12. arrays
 
PHP array 2
PHP array 2PHP array 2
PHP array 2
 

Ähnlich wie PHP Basic & Arrays

Ähnlich wie PHP Basic & Arrays (20)

Lesson 11 one dimensional array
Lesson 11 one dimensional arrayLesson 11 one dimensional array
Lesson 11 one dimensional array
 
Array andfunction
Array andfunctionArray andfunction
Array andfunction
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Programming Basics - array, loops, funcitons
Programming Basics - array, loops, funcitonsProgramming Basics - array, loops, funcitons
Programming Basics - array, loops, funcitons
 
PHP Arrays_Introduction
PHP Arrays_IntroductionPHP Arrays_Introduction
PHP Arrays_Introduction
 
array model.docx
array model.docxarray model.docx
array model.docx
 
Mod 12
Mod 12Mod 12
Mod 12
 
Lesson 2 php data types
Lesson 2   php data typesLesson 2   php data types
Lesson 2 php data types
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
 
Ppt lesson 12
Ppt lesson 12Ppt lesson 12
Ppt lesson 12
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Arrays in c++
Arrays in c++Arrays in c++
Arrays in c++
 
Array String - Web Programming
Array String - Web ProgrammingArray String - Web Programming
Array String - Web Programming
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
The Java Learning Kit Chapter 6 – Arrays Copyrigh.docx
The Java Learning Kit Chapter 6 – Arrays Copyrigh.docxThe Java Learning Kit Chapter 6 – Arrays Copyrigh.docx
The Java Learning Kit Chapter 6 – Arrays Copyrigh.docx
 
Arrays PHP 03
Arrays PHP 03Arrays PHP 03
Arrays PHP 03
 

Kürzlich hochgeladen

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Kürzlich hochgeladen (20)

Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

PHP Basic & Arrays

  • 1. Lecturer: M.Zalmai “Rahmani” rahmani.zalmai@gmail.com Web Programming II Lecture 03 PHP Basic & Arrays Azma Institute Database Department
  • 2. PHP Arrays What is an Array?  A variable is a storage area holding a number or text.The problem is, a variable will hold only one value.  An array is a special variable, which can store multiple values in one single variable.  If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: $cars1="Saab"; $cars2="Volvo"; $cars3="BMW";  However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300? The best solution here is to use an array!
  • 3. PHP Arrays What is an Array?  An array can hold all your variable values under a single name. And you can access the values by referring to the array name.  Each element in the array has its own index so that it can be easily accessed.  In PHP, there are three kind of arrays: • Numeric array - An array with a numeric index • Associative array - An array where each ID key is associated with a value • Multidimensional array - An array containing one or more arrays
  • 4. PHP Arrays Numeric Arrays  A numeric array stores each array element with a numeric index. There are two methods to create a numeric array.
  • 6. PHP Arrays Associative Arrays  An associative array, each ID key is associated with a value.  When storing data about specific named values, a numerical array is not always the best way to do it.  With associative arrays we can use the values as keys and assign values to them.
  • 9. PHP Arrays Multidimensional Arrays is Not Recommend in this Course We will study in next semester
  • 10. PHP Arrays Multidimensional Arrays  In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.