SlideShare a Scribd company logo
1 of 10
.
How to Create an Array &
types in PHP
Array Definition
 An array is collection of similar kind of data elements which
can store same data types and we can not store some of int
and some of float data types in Array.
 Traditionally an array is considered to be a collection of
homogeneous elements, which means that it cannot contain
dissimilar elements.
 But JavaScript does not follow this concept.
 A JAVASCRIPT ARRAY CAN CONTAIN HETROGENEOUS
ELEMENTS
 Thus we can say that arrays in JavaScript are similar to
structure of C language except that they are accessed using
an index.
Creating An Array
 We can create an array in 2 ways:
1. Using Array Literal
2. Using Array Constructor
Array Literals
 Array literals are written using [ ]
containing array elements separated with
commas
Syntax:
var <array name>=[value,value,. . . ];
Example:
var nums=[2,5,8,3,9];
var colors=[“red”,”green”,”blue”];
Array Literals
Another way of using Array Literals is that we can
leave the [ ] empty and fill values afterwards.
Example:
var num=[ ]; /* declares the array */
num[0]=2; /* initializes it */
num[1]=5;
num[2]=8;
num[3]=3;
num[4]=9;
Creating Array Using Constructor
 Since in JavaScript arrays are objects we can use
constructors also to create an array.
 There are 3 versions of the constructor
1. Array( )
2. Array(size)
3. Array (initializer list)
Creating Array Using Constructor
 The first constructor does not take any argument and
creates an empty array .
 Elements may be added later
Example:
var colors=new Array( );
colors[0]=“red”;
colors[1]=“green”;
colors[2]=“blue”;
Creating Array Using Constructor
 The second constructor takes an integer as argument
and creates an array of that size.
Example:
var colors=new Array(3);
colors[0]=“red”;
colors[1]=“green”;
colors[2]=“blue”;
Creating Array Using Constructor
 The third constructor takes list of values as argument
and sets array elements with it.
Example:
var colors=new Array(“red”,”blue”,”green”);
How to Create an Array & types in PHP

More Related Content

What's hot

What's hot (20)

jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Jquery
JqueryJquery
Jquery
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Sessions and cookies in php
Sessions and cookies in phpSessions and cookies in php
Sessions and cookies in php
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
Files in php
Files in phpFiles in php
Files in php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 

Viewers also liked

Array in php
Array in phpArray in php
Array in php
ilakkiya
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
Kumar
 

Viewers also liked (17)

Cloud computing
Cloud computingCloud computing
Cloud computing
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating Array
 
Arrays PHP 03
Arrays PHP 03Arrays PHP 03
Arrays PHP 03
 
Print CSS
Print CSSPrint CSS
Print CSS
 
Array in php
Array in phpArray in php
Array in php
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
 
Javascript (parte 1)
Javascript (parte 1)Javascript (parte 1)
Javascript (parte 1)
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Ecommerce final
Ecommerce finalEcommerce final
Ecommerce final
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Php array
Php arrayPhp array
Php array
 
Javascript
JavascriptJavascript
Javascript
 
Js ppt
Js pptJs ppt
Js ppt
 

Similar to How to Create an Array & types in PHP

Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
Adhoura Academy
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collections
phanleson
 

Similar to How to Create an Array & types in PHP (20)

Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
2 arrays
2   arrays2   arrays
2 arrays
 
OOPs with java
OOPs with javaOOPs with java
OOPs with java
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
 
Array lecture
Array lectureArray lecture
Array lecture
 
dizital pods session 6-arrays.ppsx
dizital pods session 6-arrays.ppsxdizital pods session 6-arrays.ppsx
dizital pods session 6-arrays.ppsx
 
dizital pods session 6-arrays.pptx
dizital pods session 6-arrays.pptxdizital pods session 6-arrays.pptx
dizital pods session 6-arrays.pptx
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collections
 
array model.docx
array model.docxarray model.docx
array model.docx
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Arrays in java.pptx
Arrays in java.pptxArrays in java.pptx
Arrays in java.pptx
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Chapter 6 java
Chapter 6 javaChapter 6 java
Chapter 6 java
 
Generics collections
Generics collectionsGenerics collections
Generics collections
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

How to Create an Array & types in PHP

  • 1. . How to Create an Array & types in PHP
  • 2. Array Definition  An array is collection of similar kind of data elements which can store same data types and we can not store some of int and some of float data types in Array.  Traditionally an array is considered to be a collection of homogeneous elements, which means that it cannot contain dissimilar elements.  But JavaScript does not follow this concept.  A JAVASCRIPT ARRAY CAN CONTAIN HETROGENEOUS ELEMENTS  Thus we can say that arrays in JavaScript are similar to structure of C language except that they are accessed using an index.
  • 3. Creating An Array  We can create an array in 2 ways: 1. Using Array Literal 2. Using Array Constructor
  • 4. Array Literals  Array literals are written using [ ] containing array elements separated with commas Syntax: var <array name>=[value,value,. . . ]; Example: var nums=[2,5,8,3,9]; var colors=[“red”,”green”,”blue”];
  • 5. Array Literals Another way of using Array Literals is that we can leave the [ ] empty and fill values afterwards. Example: var num=[ ]; /* declares the array */ num[0]=2; /* initializes it */ num[1]=5; num[2]=8; num[3]=3; num[4]=9;
  • 6. Creating Array Using Constructor  Since in JavaScript arrays are objects we can use constructors also to create an array.  There are 3 versions of the constructor 1. Array( ) 2. Array(size) 3. Array (initializer list)
  • 7. Creating Array Using Constructor  The first constructor does not take any argument and creates an empty array .  Elements may be added later Example: var colors=new Array( ); colors[0]=“red”; colors[1]=“green”; colors[2]=“blue”;
  • 8. Creating Array Using Constructor  The second constructor takes an integer as argument and creates an array of that size. Example: var colors=new Array(3); colors[0]=“red”; colors[1]=“green”; colors[2]=“blue”;
  • 9. Creating Array Using Constructor  The third constructor takes list of values as argument and sets array elements with it. Example: var colors=new Array(“red”,”blue”,”green”);