UrbanPro
true

Learn PHP from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is Array in PHP | Types of Array

Divakar Kumar
27/07/2022 0 0

An array is a special variable, which can hold more than one value at a time or you can say

An array stores 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:

 array() function is used to create an array

Example:- 

$cars = array("Volvo", "BMW", "Toyota");

In PHP, there are three types of arrays:

  • Indexed arrays - Arrays with a numeric index
  • Associative arrays - Arrays with named keys
  • Multidimensional arrays - Arrays containing one or more arrays


  • Indexed arrays - There are two ways to create indexed arrays:

    1) $cars = array("Volvo", "BMW", "Toyota");

    2) 
    $cars[0] = "Volvo";
    $cars[1] = "BMW";
    $cars[2] = "Toyota";
  • Associative arrays - Associative arrays are arrays that use named keys that you assign to them.

    There are two ways to create an associative array: 

    1) $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

    2) $age['Peter'] = "35";
    $age['Ben'] = "37";
    $age['Joe'] = "43";


Multidimensional arrays:- 

A multidimensional array is an array containing one or more arrays.

$cars = array (
  array("Volvo",22,18),
  array("BMW",15,13),
  array("Saab",5,2),
  array("Land Rover",17,15)
);



 
0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Components of Digital Marketing
Content marketing Search Engine Optimization (SEO) Paid Search (PPC) Email marketing Social Media Marketing Digital Display Marketing (Ad Ops) Web Analytics and Reporting Mobile Marketing 30...

What Are IT Industries Performance Metrics?
1. Outstanding Expectation: Eligible to get Promotion easily and good salary hike. Always preferrable to go abroad. 2. Exceed Expectation: Can get Promotion as per schedule of company with good salary...

What Is PHP?
PHP stands for PHP: Hypertext Preprocessor PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use PHP files can contain text,...

Basics about the PHP
Basics: Father of PHP Rasmus Lerdorf. Developed in 1994. Existing in 1999 PHP stands for: PHP: Hypertext Preprocessor. PHP is an Open Source Software (OSS) free to download and Use. PHP is...

Core PHP v/s PHP Frameworks
PHP Frameworks: Framework is a piece of software by which one can develop large enterprise, robust & secure software applications. Frameworks provide straight forward flow and strict guidelines by...
X

Looking for PHP Classes?

The best tutors for PHP Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn PHP with the Best Tutors

The best Tutors for PHP Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more