View Full Version : Problem in inserting array in array

09-03-2009, 10:37 AM
Hi All,

I have different two dimensional arrays .. I need to insert all these arrays in one array in different indexes .. can any one tell how to do this and how to fetch the array elements..

Thanx in advance ...

09-03-2009, 11:09 AM
Not so sure about what you mean exactly, but his is the basic concept.

$a = array(1 => array(2 => "Two!", 3 => "Three!"), 2 => array(4 => "Four"));

echo $a[1][2];

That outputs "Two!" because we're referencing the 1 index point in the first array, then we're referencing the 2, which holds the value of "Two!"

09-03-2009, 02:46 PM
This is basically the same thing Zangeel said, but written out more verbose:

$a = array();
$b = array();
$a[0] = "one";
$a[1] = "two";
$b[0] = "uno";
$b[1] = "dos";

$c = array();
$c[0] = $a;
$c[1] = $b

print($c[0][0]); // one
print($c[0][1]); // two
print($c[1][0]); // uno
print($c[1][1]); // dos