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

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

PHP
It is the base for many of the ecommerce websites. Many of the CMS develpoped in PHP platform.If programming cant done inititally try to think for logics and develop writing algorithms. Any doubts divyaravindiran@gmail.com.

Read Your Gmail Emails Using PHP and IMAP
Hello Friends ,Recently I have worked on drip email campaign project for that I need to read emails using PHP From the gmail inbox. Here is the simple example for Read emails from the gmail: To start...

How to create your website with PHP?
PHP is a server-side programming language used to create web pages that are more interactive than their HTML counterparts. PHP also optimizes the speed of web pages since processing occurs on the server...

Happiness Or Satisfaction: How To Quit Your Day Job?
Four years ago on a sunny April morning, I slinked into my new office building, suit slightly too big, 24-years-old and clueless. It was my first day working at a large, prestigious Organization. The...
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