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 (20)

Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
 
Strings in C
Strings in CStrings in C
Strings in C
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Javascript
JavascriptJavascript
Javascript
 
C++ string
C++ stringC++ string
C++ string
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 
Learning HTML
Learning HTMLLearning HTML
Learning HTML
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Html ppt
Html pptHtml ppt
Html ppt
 
Html and css
Html and cssHtml and css
Html and css
 

Viewers also liked

Viewers also liked (18)

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
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Javascript
JavascriptJavascript
Javascript
 
Js ppt
Js pptJs ppt
Js ppt
 

Similar to How to Create an Array & types in PHP

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

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 

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”);