0% found this document useful (0 votes)
18 views

PHP Array

Uploaded by

Sagar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

PHP Array

Uploaded by

Sagar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Array

• An array is assigned to a single variable, but it can hold dozens of individual


pieces of information.
• Within every array element there are two parts: the value and a unique key
• In PHP, the array() function is used to create an array.
• An array in php is actually an ordered map.
• It associates values to keys...
• Key plays an important role in the process of accessing and manipulating array
elements.
• Keys can either be non-negative integers or strings.
Indexed Array vs Associative array

 Key of indexed array is integer which starts with 0.


 Indexed array are used when we identify things with their position.
 Associative arrays have strings as keys and behave more like two-columns table.
Indexed array
 There are two ways to create indexed arrays:
 The index can be assigned automatically (index always starts at 0), like this:
                    $cars = array("Volvo", "BMW", "Toyota");
 or the index can be assigned manually:
                                 $cars[0] = "Volvo";
                                 $cars[1] = "BMW";
                                 $cars[2] = "Toyota";
Associative Array

 Associative arrays are arrays that use named keys that you assign to them.
 There are two ways to create an associative array: 
                 $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
 or:
                                $age['Peter'] = "35";
                                $age['Ben'] = "37";
                                $age['Joe'] = "43";

You might also like