PHP ARRAYS - PHP LESSON 13 STUDENTSBLOG100


Arrays in php are used to hold one or more values in a single variable. These values can be retrieved by its key value.That is, consider we have stored five values in an array. ex)array[a,b,c,d,e]. first value a's address is array[0], second value b's address is array[1], and so on. In associative array method, we can access array contents by named key to

Php Array Types:
There are three types in php arrays, they are
  • Indexed arrays - Arrays with index
  • Associative arrays - Arrays with keys
  • Multidimensional arrays - Nested arrays

PHP Indexed Array:
This type of array can store numbers, string and objects too. But the index values will be in numeric format starting from zero.

Syntax:
Two ways to implement php indexed array are..


Example:

Output:
Students are Student1
Student2
Student3

PHP Associative Array:
Associative array will have their index as string. And it has all the functionalities of indexed array.

Syntax:

Two ways to implement php associative array are..

Example:

Output:
Student1 is 25 years old
Student2 is 28 years old
Student3 is 37 years old

PHP Multidimensional Array:
An array inside an array is called as Multidimensional array. The fist value of first inner array can be accessed by $array [0][0] , second value by $array [0][1] and so on. And first value of second inner array can be accessed by $array [1][0], second value by $array [1][1] and so on. See the example, you will get an idea.

Syntax:
Two ways to implement php associative array are..

Example:

Output:
Student Name : Student1, Age : 22, Location : TamilNadu
Student Name : Student2, Age : 15, Location : Delhi
Student Name : Student3, Age : 25, Location : London
Student Name : Student4, Age : 17, Location : Bombay

Lesson 12 Previous | Main Page | Next Lesson 14

Previous
Next Post »