RE: [PHP] Is there such an array like $array[][]?
| From: | Tim Ward | Date: | Wed, 25 Apr 2001 08:27:32 +0000 |
| Subject: | RE: [PHP] Is there such an array like $array[][]? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-50258@lists.php.net to get a copy of this message | ||
A multi dimensional array is a matrix. if $array[1][2][3] was an element of
a multi-dimensional array then it would directly accessible as an element of
$array. It isn't. $array (and $array[n]) only contain arrays.
If $array was a 3-d array then ...
$array[1][2][3] = "fred";
if (in_array("fred", $array)) echo "fred found"; // prints "fred
found"
Tim Ward
Senior Systems Engineer
Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html
> -----Original Message-----
> From: Robert V. Zwink [mailto:rzwink@microcenter.com]
> Sent: 24 April 2001 15:20
> To: Tim Ward
> Cc: Php-General@Lists.Php.Net
> Subject: RE: [PHP] Is there such an array like $array[][]?
>
>
> I don't understand your different definitions: "muti-dimensional" and
> "array of arrays"
>
> From the manual:
> Multi-Dimensional Arrays
> Multi-dimensional arrays are actually pretty simple. For each
> dimension of
> the array, you add another [key] value to the end:
>
> > Tim Ward wrote:
> > <snip>
> > What looks like a 2d array is fact an array of arrays (and so
> > on). If it's built right this can be treated as a multi-d
> array in many
> > ways ... but not all.
>
> I wonder if you can help me understand this concept by giving
> an example of
> what is possible with 1-dim arrays, but not with 3-dim arrays?
>
> From my point of view the only difference is writing a custom
> comparison
> function when sorting, though this does seem logical considering the
> additional complexity of multiple dimensions.
>
> Thanks for your help.
>
> Robert Zwink
>
>
> -----Original Message-----
> From: Tim Ward [mailto:tim.ward@stivesdirect.com]
> Sent: Tuesday, April 24, 2001 9:54 AM
> To: 'Robert V. Zwink'
> Subject: RE: [PHP] Is there such an array like $array[][]?
>
>
> my point was that what appear to be multi-dimensional arrays
> in php are not
> that at all. What looks like a 2d array is fact an array of
> arrays (and so
> on). If it's built right this can be treated as a multi-d
> array in many ways
> ... but not all.
>
> There seem to be a lot of queries from people confused about
> how to deal
> with arrays of arrays and this often stems from a
> misconception that they
> are actually multi-d arrays.
>
> Tim Ward
> Senior Systems Engineer
>
> Please refer to the following disclaimer in respect of this message:
> http://www.stivesdirect.com/e-mail-disclaimer.html
>
>
> > -----Original Message-----
> > From: Robert V. Zwink [mailto:rzwink@microcenter.com]
> > Sent: 24 April 2001 14:33
> > To: Tim Ward; php-general@lists.php.net
> > Subject: RE: [PHP] Is there such an array like $array[][]?
> >
> >
> > I have used the function usort() to sort multi-dimensional
> > arrays before.
> > It might be a challenge to write the comparison function, but it is
> > possible. I use 3-dim arrays all of the time. Makes for a
> > bit cleaner code
> > IMHO.
> >
> > I suppose one thing to consider, is that if you have an
> enormous 3-dim
> > array, you are probably doing something wrong. Generating a
> > really big
> > array can be resource intense, and can slow you page down
> > exponentially.
> > Select only parts of the recordset, or smaller chuck of the
> > file for better
> > execution, but if your application requires a large 3-dim
> > array, it works
> > just fine for me.
> >
> > Robert Zwink
> >
> > -----Original Message-----
> > From: Tim Ward [mailto:tim.ward@stivesdirect.com]
> > Sent: Wednesday, April 18, 2001 8:06 AM
> > To: 'php-general@lists.php.net'
> > Subject: RE: [PHP] Is there such an array like $array[][]?
> >
> >
> > 1. there are no multi-dimensional arrays in php, just
> single dimension
> > arrays each element of which may be an array (or any other
> > variable type).
> > If you make every element of an array an array of size x, you
> > will get what
> > can be used as a multi-dimensional array. But if you forget
> > what it really
> > is, you'll run into problems like expecting to be able to sort
> > $array[$x][$y] by $y.
> > 2. because of this you can have as many levels of an array as
> > you want.
> >
> > try :
> > $array[][][][] = "fred";
> > foreach($array as $level1)
> > foreach($level1 as $level2)
> > foreach($level2 as $level3)
> > foreach($level3 as $value)
> > echo($value);
> >
> > Tim Ward
> > Senior Systems Engineer
> >
> > Please refer to the following disclaimer in respect of this message:
> > http://www.stivesdirect.com/e-mail-disclaimer.html
> >
> >
> > > -----Original Message-----
> > > From: Plutarck [mailto:aemuli@spamclause-yahoo.com]
> > > Sent: 17 April 2001 17:42
> > > To: php-general@lists.php.net
> > > Subject: Re: [PHP] Is there such an array like $array[][]?
> > >
> > >
> > > PHP can be a tad screwy with how it handles multi-dimensional
> > > arrays, but
> > > yes PHP handles them. No real speed problems with them either.
> > >
> > > But you may just want to use an associative array like:
> > >
> > > $loc = array("y" => $y, "x" => $x);
> > >
> > > Then just use $loc["y"] and $loc["x"].
> > >
> > > Just another option, but feel free to use multi-dimensional
> > > arrays. Just be
> > > aware that PHP supports only two dimensions (so $array[][][]
> > > will not work),
> > > and if you try and get fancy with sort() and count() you are
> > > going to give
> > > yourself a migraine.
> > >
> > >
> > > --
> > > Plutarck
> > > Should be working on something...
> > > ...but forgot what it was.
> > >
> > >
> > > "Jack Dempsey" <dempsejn@georgetown.edu> wrote in message
> > > news:3ADC731D.654BEE7@georgetown.edu...
> > > > yes, that's a multi-dimensional array, which is fine in php (and
> > > > everything else i can think of =P)...
> > > >
> > > > -jack
> > > >
> > > > Scott Fletcher wrote:
> > > > >
> > > > > Hi! I am wondering if there is such a php array that can
> > > take care of
> > > the x
> > > > > and y axis data. I figure that using this array type,
> > > $axis[$x][$y]
> > > would
> > > > > do the trick. Would it work? If not, then education me
> > > on what would
> > > work!
> > > > > Thanks!
> > > > >
> > > > > Scott
> > > > >
> > > > > --
> > > > > PHP General Mailing List (http://www.php.net/)
> > > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > > > For additional commands, e-mail:
> php-general-help@lists.php.net
> > > > > To contact the list administrators, e-mail:
> > > php-list-admin@lists.php.net
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > > For additional commands, e-mail: php-general-help@lists.php.net
> > > > To contact the list administrators, e-mail:
> > > php-list-admin@lists.php.net
> > > >
> > >
> > >
> > >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail:
> > php-list-admin@lists.php.net
> >
>