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

Necessity of Theory and Practical in Computer Science.
Upon studying a subject both theory and practical are important. Usually many schools concentrate more on theory and the marks not on the practical. Other and opposite kind of people prefer practical...

Try to clear up the basics, if basics are clear then you can go ahead with any difficult problem
Hey guys, To all the students i just want to convey that just clear up your basics so that they can help you solve anyu problem and you would achieve a great success. Regards, Ishani Chakraborty

Learn Conceptually
Whenever you try to learn something, understand the concepts well. This will not only fix the idea in your mind but also help you comprehend the process.
S

Shweta Chauhan

0 0
0

Be Carefull While Uploading A file To Server Using PHP
With PHP, it is easy to upload files to the server. However, with ease comes danger, so always be careful when allowing file uploads. 1. Configure The "php.ini" File: First, ensure that PHP is configured...

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