By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,723 Members | 1,414 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,723 IT Pros & Developers. It's quick & easy.

Group an array

P: n/a
i have the following array:

Array
(
[0] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =20
)

[1] =Array
(
[0] =HRPC
[1] =920589205210538
[2] =1
)

[2] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =2
)

)
is it possible to group the items in the array and order by name to
output the following:

Array
(
[0] =Array
(
[0] =HRPC
[1] =920589205210538

[2] =1
)

[1] =Array
(
[0] =Leamore Windows Ltd

[1] =553398833511417
[2] =22
)
)

Jan 29 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
cr*************@gmail.com wrote:
i have the following array:

Array
(
[0] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =20
)

[1] =Array
(
[0] =HRPC
[1] =920589205210538
[2] =1
)

[2] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =2
)

)
is it possible to group the items in the array and order by name to
output the following:

Array
(
[0] =Array
(
[0] =HRPC
[1] =920589205210538

[2] =1
)

[1] =Array
(
[0] =Leamore Windows Ltd

[1] =553398833511417
[2] =22
)
)
Hi,

Have a look at usort()
http://nl2.php.net/manual/en/function.usort.php

With usort you can define your own sortingrules.

Regards,
Erwin Moller
Jan 29 '07 #2

P: n/a
On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
<si******************************************@spam yourself.comwrote:
cr*************@gmail.com wrote:
>i have the following array:

Array
(
[0] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =20
)

[1] =Array
(
[0] =HRPC
[1] =920589205210538
[2] =1
)

[2] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =2
)

)
is it possible to group the items in the array and order by name to
output the following:

Array
(
[0] =Array
(
[0] =HRPC
[1] =920589205210538

[2] =1
)

[1] =Array
(
[0] =Leamore Windows Ltd

[1] =553398833511417
[2] =22
)
)

Hi,

Have a look at usort()
http://nl2.php.net/manual/en/function.usort.php

With usort you can define your own sortingrules.

Regards,
Erwin Moller
The OP may want array_unique. After which, they could sort.

@the OP: you'll probably have to write a recursive function using
array_unique to handle multi-dimensional arrays.

--
Curtis
Jan 30 '07 #3

P: n/a


On 30 Jan, 10:56, Curtis <dyers...@verizon.netwrote:
On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller

<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
craig.keight...@gmail.com wrote:
i have the following array:
Array
(
[0] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =20
)
[1] =Array
(
[0] =HRPC
[1] =920589205210538
[2] =1
)
[2] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =2
)
)
is it possible to group the items in the array and order by name to
output the following:
Array
(
[0] =Array
(
[0] =HRPC
[1] =920589205210538
[2] =1
)
[1] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =22
)
)
Hi,
Have a look at usort()
http://nl2.php.net/manual/en/function.usort.php
With usort you can define your own sortingrules.
Regards,
Erwin MollerThe OP may want array_unique. After which, they could sort.

@the OP: you'll probably have to write a recursive function using
array_unique to handle multi-dimensional arrays.

--
Curtis
The tips provided look very useful - but i wonder where the data's
actually coming from? If it's from a sql database then it would far
simpler to do the manipulations there.

Jan 30 '07 #4

P: n/a
On Jan 30, 12:31 pm, "strawberry" <zac.ca...@gmail.comwrote:
On 30 Jan, 10:56, Curtis <dyers...@verizon.netwrote:


On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
craig.keight...@gmail.com wrote:
>i have the following array:
>Array
>(
> [0] =Array
> (
> [0] =Leamore Windows Ltd
> [1] =553398833511417
> [2] =20
> )
> [1] =Array
> (
> [0] =HRPC
> [1] =920589205210538
> [2] =1
> )
> [2] =Array
> (
> [0] =Leamore Windows Ltd
> [1] =553398833511417
> [2] =2
> )
>)
>is it possible to group the items in the array and order by name to
>output the following:
>Array
>(
> [0] =Array
> (
> [0] =HRPC
> [1] =920589205210538
> [2] =1
> )
> [1] =Array
> (
> [0] =Leamore Windows Ltd
> [1] =553398833511417
> [2] =22
> )
>)
Hi,
Have a look at usort()
>http://nl2.php.net/manual/en/function.usort.php
With usort you can define your own sortingrules.
Regards,
Erwin MollerThe OP may want array_unique. After which, they could sort.
@the OP: you'll probably have to write a recursive function using
array_unique to handle multi-dimensional arrays.
--
Curtis

The tips provided look very useful - but i wonder where the data's
actually coming from? If it's from a sql database then it would far
simpler to do the manipulations there.- Hide quoted text -

- Show quoted text -
the result is produced from 2 separate queries producing results from
2 separate tables. I appreciate that it would be easier to manipulate
from the sql leayer but the tables contain individual data elements.

Jan 31 '07 #5

P: n/a
On 31 Jan, 08:49, craig.keight...@gmail.com wrote:
On Jan 30, 12:31 pm, "strawberry" <zac.ca...@gmail.comwrote:


On 30 Jan, 10:56, Curtis <dyers...@verizon.netwrote:
On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
craig.keight...@gmail.com wrote:
i have the following array:
Array
(
[0] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =20
)
[1] =Array
(
[0] =HRPC
[1] =920589205210538
[2] =1
)
[2] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =2
)
)
is it possible to group the items in the array and order by name to
output the following:
Array
(
[0] =Array
(
[0] =HRPC
[1] =920589205210538
[2] =1
)
[1] =Array
(
[0] =Leamore Windows Ltd
[1] =553398833511417
[2] =22
)
)
Hi,
Have a look at usort()
http://nl2.php.net/manual/en/function.usort.php
With usort you can define your own sortingrules.
Regards,
Erwin MollerThe OP may want array_unique. After which, they could sort.
@the OP: you'll probably have to write a recursive function using
array_unique to handle multi-dimensional arrays.
--
Curtis
The tips provided look very useful - but i wonder where the data's
actually coming from? If it's from a sql database then it would far
simpler to do the manipulations there.- Hide quoted text -
- Show quoted text -

the result is produced from 2 separate queries producing results from
2 separate tables. I appreciate that it would be easier to manipulate
from the sql leayer but the tables contain individual data elements.- Hide quoted text -

- Show quoted text -
So do a UNION!

Jan 31 '07 #6

P: n/a
On Jan 31, 9:53 am, "Captain Paralytic" <paul_laut...@yahoo.com>
wrote:
On 31 Jan, 08:49, craig.keight...@gmail.com wrote:


On Jan 30, 12:31 pm, "strawberry" <zac.ca...@gmail.comwrote:
On 30 Jan, 10:56, Curtis <dyers...@verizon.netwrote:
On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
craig.keight...@gmail.com wrote:
>i have the following array:
>Array
>(
> [0] =Array
> (
> [0] =Leamore Windows Ltd
> [1] =553398833511417
> [2] =20
> )
> [1] =Array
> (
> [0] =HRPC
> [1] =920589205210538
> [2] =1
> )
> [2] =Array
> (
> [0] =Leamore Windows Ltd
> [1] =553398833511417
> [2] =2
> )
>)
>is it possible to group the items in the array and order by name to
>output the following:
>Array
>(
> [0] =Array
> (
> [0] =HRPC
> [1] =920589205210538
> [2] =1
> )
> [1] =Array
> (
> [0] =Leamore Windows Ltd
> [1] =553398833511417
> [2] =22
> )
>)
Hi,
Have a look at usort()
>http://nl2.php.net/manual/en/function.usort.php
With usort you can define your own sortingrules.
Regards,
Erwin MollerThe OP may want array_unique. After which, they could sort.
@the OP: you'll probably have to write a recursive function using
array_unique to handle multi-dimensional arrays.
--
Curtis
The tips provided look very useful - but i wonder where the data's
actually coming from? If it's from a sql database then it would far
simpler to do the manipulations there.- Hide quoted text -
- Show quoted text -
the result is produced from 2 separate queries producing results from
2 separate tables. I appreciate that it would be easier to manipulate
from the sql leayer but the tables contain individual data elements.- Hide quoted text -
- Show quoted text -

So do a UNION!- Hide quoted text -

- Show quoted text -
Thanks, but i didn't know of the UNION syntax in mysql. Its seems to
work for me. Thanks again

Jan 31 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.