Creating a Multidimensional Array : Multidimensional Array « Data Structure « PHP






Creating a Multidimensional Array

 
<?php

    $myarray = array('mykey'=> 'myvalue','key2'=> array(1, 2, 3, 4));

    $sub_array[] = 1;
    $sub_array[] = 2;
    $sub_array[] = 3;
    $sub_array[] = 4;
    $example['mykey'] = 'myvalue';
    $example['key2']  = $sub_array;

    $anotherarray['mykey'] = 'myvalue';
    $anotherarray['key2'][] = 1;
    $anotherarray['key2'][] = 2;
    $anotherarray['key2'][] = 3;
    $anotherarray['key2'][] = 4;
?>
  
  








Related examples in the same category

1.Reference element in multidimensional Arrays
2.Defining a Multidimensional Array
3.Looping Through a Multidimensional Array
4.Displaying a Multidimensional Array using For each
5.Accessing multidimensional array elements
6.Creating Multidimensional Arrays
7.Sorting Multidimensional Arrays
8.Multidimensional array element value interpolation
9.Displaying Multidimensional Arrays
10.Displaying a multidimensional array
11.Find the Maximum Value in a Multidimensional Array
12.Generating fixed-width field data records without
13.Manipulating multidimensional arrays