Re: RE: Multi-dimensional array issue

From: Date: Tue, 21 Aug 2001 09:40:53 +0000
Subject: Re: RE: Multi-dimensional array issue
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-63662@lists.php.net to get a copy of this message
> ---------- > From: Ken Hopkins [SMTP:hoppy@austin.rr.com] > Sent: 20 August 2001 21:02 > To: php-general@lists.php.net > 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. The first level of element will be $basearray[$key] = $value $basearray[$key2] = $value $basearray[$key3] = $value $basearray[$key4] = $value the extra array $basearray[$key5][$extraarraykey1] = $value $basearray[$key5][$extraarraykey2] = $value > > 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:hoppy@austin.rr.com > > <? > > $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>"; > ?> > >

« previous php.general (#63662) next »