Php two dimensional array

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

examples of single and multi-dimensional arrays

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
Please help…

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',
    'address' => 'Somewhere',
    'job' => 'pirate'
  ),

  1 => array (
    'name' => 'Ken',
    'address' => 'Unknown',
    'job' => 'Ninja'
  )
)

There is no limit on the number of mathematical dimensions you can have in the language, though memory limitations on the script will quickly catch you if you aren’t careful - and I have built an array with as many as 6 dimensions for complicated reports. Parsing time becomes a concern whenever you have that many levels though as it won’t scale well if a large number is put into one of the lower dimensions. The syntax is just to keep adding to the tail, like this.


$patient[$episode][$claim][$bill][$procedure]