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

Hiding .php extension Using HTACESS File
If you wish to hide.php extension from your website, then create a .htaccess file in your project root and paste the following code : RewriteEngine On RewriteCond %{THE_REQUEST} ^{3,}\s/(.+)\.php*...

How to be a good developer?
I think practice more and read less.see what the logic in the programs then you must be a good developer
B

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

Software Development Training In Jaipur
Satyam Web Solution provides website designing &development and software designing &development training in Jaipur for various stream’s students. MCA 6 month Industrial Training/Internship B....

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...
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