The first thing is that 2-dimensional arrays don't really exist in  php. Any
element of any array can be another array. The second important point is
that all php arrays are associative. If you don't declare the key of an
element (e.g. $out[] = "fred") when creating it you get the next integer
available as the key. Your initial declaration creates ...

$out[0] = $name;
$out[1] = $srch;
$out[2] = $sel;
$out[3] = $case;
$out[$qvalues][0] = $vals;
$out[$qvalues][1] = $valtypes;

with $name, etc. being whatever the variables are at the time the array is
initialised.

What I think you wanted (I'm not entirely sure) is more along the lines of
...
for ($i=0; $I < $num_out; $I++)
        $out[] = array("name"=>$name, "srch"=>$srch, "sel"=>$sel,
"case"=>$case, $qvalues => array($vals, $valtypes));

I'm not entirely sure what you're trying to do but I hope this points you in
the right direction. 

Tim
        ----------
        From:  Ken Hopkins [SMTP:[EMAIL PROTECTED]]
        Sent:  20 August 2001 21:02
        To:  [EMAIL PROTECTED]
        Subject:  Multi-dimensional array issue

        Hi from a recent PHP convert,

        Having a heck of a time declaring and accessing 2 dimensional info
in an array.
        any input on where to start looking for the answer would be greatly
appreciated.

        I want to have a base array of 5 elements. The first 4 elements are
variables, and the fifth is an array of 2 elements.
        seemed harmless enough at the time;)

        Coding conventions suggest access to the first level of elements is:
        $basearray[base_numerical_offset][$basearray_variable]
        and this works great for accessing the first 4 elements of the base
array.

        Accessing the fifth elements' variables in the next dimension is
where it fails for me:
        
$basearray[base_numerical_offset][$subarray][sub_numerical_offset][$subarray
_variable]

        The documentation/snippets/samples, etc. have been to no avail;
still can't get to elements in the
        second dimension properly. Attempts to populate the second level
array trahses the entire structure.

        I have the following declaration:
        $out => array($name, $srch, $sel, $case, $qvalues => array($vals,
$valtypes);
            $out is the name of the base array
            $qvalues is the name of the sub-array under the base array
"$out"
        I need for each $out array to consist of a name, srch, sel, case and
then a variable number of qvalues array elements that each have single vals
and valtypes elements.

        Use the following snippet to see what happens; it's not what I had
hoped to see.
        I hope I'm just doing something wrong..

        Thanks, Ken.
        mailto:[EMAIL PROTECTED]

        <?

         $out = array($name, $srch, $sel, $case, $qvalues => array($vals,
$valtypes));
        echo "<pre>";
         $out[0][$name] = "free";
         $out[1][$name] = "next";
         for ($i=0; $i<2; $i++)
            {
               echo "<br>   OutIndex: ", $i, "     Name: ", $out[$i][$name];
            }

           $out[0][$srch] = "outfreesrch";
           $out[0][$sel] = "outfreesel";
           $out[0][$case] = "outfreecase";
           $out[0][$qvalues][0][$vals] = "outfreeqval0";
           $out[0][$qvalues][0][$valtypes] = "outfreeqtype0";
           $out[0][$qvalues][1][$vals] = "outfreeqval1";
           $out[0][$qvalues][1][$valtypes] = "outfreeqtype1";
           echo "<br>Basearray index : ", 0, "\n";
           echo "<br>               name : ", $out[0][$name], "\n";
           echo "<br>               srch : ", $out[0][$srch], "\n";
           echo "<br>               sel  : ", $out[0][$sel], "\n";
           echo "<br>               case : ", $out[0][$case], "\n";
           echo "<br>   Subarray index      : 0 \n";
           echo "<br>              vals     : ",
$out[0][$qvalues][0][$vals], "\n";
           echo "<br>              valtypes : ",
$out[0][$qvalues][0][$valtypes], "\n";
           echo "<br>   Subarray index      : 1 \n";
           echo "<br>              vals     : ",
$out[0][$qvalues][1][$vals], "\n";
           echo "<br>              valtypes : ",
$out[0][$qvalues][2][$valtypes], "\n";
           echo"<br><br>";
           $out[1][$srch] = "outnextsrch";
           $out[1][$sel] = "outnextsel";
           $out[1][$case] = "outnextcase";
           $out[1][$qvalues][0][$vals] = "outnextqval0";
           $out[1][$qvalues][0][$valtypes] = "outnextqtype0";
           $out[1][$qvalues][1][$vals] = "outnextqval1";
           $out[1][$qvalues][1][$valtypes] = "outnextqtype1";
           echo "<br>Basearray index : ", 1, "\n";
           echo "<br>               name : ", $out[1][$name], "\n";
           echo "<br>               srch : ", $out[1][$srch], "\n";
           echo "<br>               sel  : ", $out[1][$sel], "\n";
           echo "<br>               case : ", $out[1][$case], "\n";
           echo "<br>   Subarray index      : 0 \n";
           echo "<br>              vals     : ",
$out[1][$qvalues][0][$vals], "\n";
           echo "<br>              valtypes : ",
$out[1][$qvalues][0][$valtypes], "\n";
           echo "<br>   Subarray index      : 1 \n";
           echo "<br>              vals     : ",
$out[1][$qvalues][1][$vals], "\n";
           echo "<br>              valtypes : ",
$out[1][$qvalues][1][$valtypes], "\n";
        echo "</pre>";
        ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to