Organizational Research By

Surprising Reserch Topic questions - Question:how to use PHP Multidimensional Arrays?

An array can also contain another array as a value, which in turn can hold other arrays as well. In such a way we can create two- or three-dimensional arrays:
// A two-dimensional array:
$cars = array

PHP - Multidimensional Arrays

A multidimensional array is an array containing one or more arrays.

In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.

In this example we create a multidimensional array, with automatically assigned ID keys:
$families = array

The array above would look like this if written to the output:
[Griffin] => Array
  [0] => Peter
  [1] => Lois
  [2] => Megan
[Quagmire] => Array
  [0] => Glenn
[Brown] => Array
  [0] => Cleveland
  [1] => Loretta
  [2] => Junior
Example 2

Lets try displaying a single value from the array above:
echo "Is " . $families['Griffin'][2] .
" a part of the Griffin family?";

The code above will output:
Is Megan a part of the Griffin family?

asked Sep 13, 2013 in PHP by rajesh
edited Sep 12, 2013
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.