I have an array in PHP 3 that I build like this;

$var_list[$i] -- first level
$var_list[$var_list[$i] ][$j] --2nd level
$var_list[$var_list[$var_list[$i] ][$j]][$k] --3rd level

I use loops as follows..

for ($i=0; $i < count1; $i++ ) {
$var_list[$i] = $theval;
for ($j=0; $j < count1; $j++ ) {
$var_list[$var_list[$i] ][$j]=$anyval;
for ($k=0; $k < count1; $k++ ) {

$var_list[$var_list[$var_list[$i] ][$j]][$k]=$someval;

     }
 }

}

The problem is the $k value in the inner loop always appears to be "0" so I never get a past the 0 row of the 3rd level & my values over-write each other..

Any ideas??

    It would probably be helpful if you gives us an idea of what your code is supposed to do.

      I am trying to build an array that I use for drop-down boxes & navigation

      It works fine for any value of 0->0->n->n->

      socks->size1->cotton->red
      0->0>->0->0

      However, the problem arises with value x, the x value always writes to position 0. I have confirmed this by retreiving values from the array using;

      echo ".$var[$var[$var[0]][0]][0]. " and
      echo ".$var[$var[$var[0]][0]][1]. "

      They both echo the same value "Nylon"..

      0->0->x->n

      level0--
      level1--
      level2
      level3--

      socks-0
      size1-0
      cotton-0
      red-1
      blue-2
      nylon-1
      red-0
      blue-1
      green-2
      size2-1
      cotton-0
      red-1
      blue-2

      Shoes-0

        Why don't you use a class object? It would be much simpler to handle the data.

        Frag

          7 days later

          I found an answer......

          Put the different values in different arrays..

          $bob1[$i]
          $bob2[$i][$j]
          $bob3[$i][$j][$k]

          etc.........

          For some reason PHP did not seem capable of handling the math to build an array if it got past $k>0.....

          Works like a charm.

            Write a Reply...