91-9990449935 0120-4256464 |
PHP ArraysPHP array is an ordered map (contains value on the basis of key). It is used to hold multiple values of similar type in a single variable. Advantage of PHP ArrayLess Code: We don't need to define multiple variables. Easy to traverse: By the help of single loop, we can traverse all the elements of an array. Sorting: We can sort the elements of array. PHP Array TypesThere are 3 types of array in PHP.
PHP Indexed ArrayPHP index is represented by number which starts from 0. We can store number, string and object in the PHP array. All PHP array elements are assigned to an index number by default. There are two ways to define indexed array: 1st way: 2nd way: ExampleFile: array1.phpOutput:
Season are: summer, winter, spring and autumn
File: array2.php
Output:
Season are: summer, winter, spring and autumn
Click me for more details...
PHP Associative ArrayWe can associate name with each array elements in PHP using => symbol. There are two ways to define associative array: 1st way: 2nd way: ExampleFile: arrayassociative1.phpOutput: Sonoo salary: 350000 John salary: 450000 Kartik salary: 200000 Output: Sonoo salary: 350000 John salary: 450000 Kartik salary: 200000 PHP Multidimensional ArrayClick me for more details...
Next TopicPHP Indexed Array
|