# Php two dimensional array

I need an example for n dimensional array with insertion operation in it
can any one help me…

I’m not too sure what you are asking but here goes:

``````<?php

// create two arrays
\$flowers = array('rose', 'petunia', 'lilly');
\$dogs = array('fido', 'spot', 'lab', 'puffy');

// create multidimensional array
\$multiDimensionalArray = array('flowers'=>\$flowers, 'dogs'=>\$dogs);

// add a dog
\$multiDimensionalArray['dogs'][] = 'pooch';

// show result
echo "multiDimensionalArray= \
<pre>\
";
print_r (\$multiDimensionalArray);
echo "</pre>\
";

?>
``````

I explain my problem in detail

I am using an array whose dimension(1 dimensional or 2 dimensional or multi dimensional) changes dynamically.

Input:sin(x)
Output :should be

Array ( [a0] => x [a1] => sin(a0))

how to create array for the above structure

banu, you need one or more looping structures depending on the algorithm you are coding. See

http://us.php.net/manual/en/control-structures.intro.php

for example, the following would create values sin(0) to sin(9):

``````<?php

\$x = 0;
\$result = array();
while (\$x < 10) {
\$result[] = array(\$x, sin(\$x));
\$x++;
}

// show result
echo "result= \
<pre>\
";
print_r (\$result);
echo "</pre>\
";

?>
``````

A clearer example. Here’s how you would access the members of a multidimensional array.

``````\$table[\$row][\$field];
``````

This declaration format makes the multidimensional nature more clear.

``````
\$table => array (
0 => array (
'name' => 'John',
'job' => 'pirate'
),

1 => array (
'name' => 'Ken',
``````