Group an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • craig.keightley@gmail.com

    Group an array

    i have the following array:

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

    [1] =Array
    (
    [0] =HRPC
    [1] =92058920521053 8
    [2] =1
    )

    [2] =Array
    (
    [0] =Leamore Windows Ltd
    [1] =55339883351141 7
    [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] =92058920521053 8

    [2] =1
    )

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

    [1] =55339883351141 7
    [2] =22
    )


    )

  • Erwin Moller

    #2
    Re: Group an array

    craig.keightley @gmail.com wrote:
    i have the following array:
    >
    Array
    (
    [0] =Array
    (
    [0] =Leamore Windows Ltd
    [1] =55339883351141 7
    [2] =20
    )
    >
    [1] =Array
    (
    [0] =HRPC
    [1] =92058920521053 8
    [2] =1
    )
    >
    [2] =Array
    (
    [0] =Leamore Windows Ltd
    [1] =55339883351141 7
    [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] =92058920521053 8
    >
    [2] =1
    )
    >
    [1] =Array
    (
    [0] =Leamore Windows Ltd
    >
    [1] =55339883351141 7
    [2] =22
    )
    >
    >
    )
    Hi,

    Have a look at usort()


    With usort you can define your own sortingrules.

    Regards,
    Erwin Moller

    Comment

    • Curtis

      #3
      Re: Group an array

      On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c omwrote:
      craig.keightley @gmail.com wrote:
      >
      >i have the following array:
      >>
      >Array
      >(
      > [0] =Array
      > (
      > [0] =Leamore Windows Ltd
      > [1] =55339883351141 7
      > [2] =20
      > )
      >>
      > [1] =Array
      > (
      > [0] =HRPC
      > [1] =92058920521053 8
      > [2] =1
      > )
      >>
      > [2] =Array
      > (
      > [0] =Leamore Windows Ltd
      > [1] =55339883351141 7
      > [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] =92058920521053 8
      >>
      > [2] =1
      > )
      >>
      > [1] =Array
      > (
      > [0] =Leamore Windows Ltd
      >>
      > [1] =55339883351141 7
      > [2] =22
      > )
      >>
      >>
      >)
      >
      Hi,
      >
      Have a look at usort()

      >
      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

      Comment

      • strawberry

        #4
        Re: Group an array



        On 30 Jan, 10:56, Curtis <dyers...@veriz on.netwrote:
        On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
        >
        >
        >
        <since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
        craig.keight... @gmail.com wrote:
        >
        i have the following array:
        >
        Array
        (
        [0] =Array
        (
        [0] =Leamore Windows Ltd
        [1] =55339883351141 7
        [2] =20
        )
        >
        [1] =Array
        (
        [0] =HRPC
        [1] =92058920521053 8
        [2] =1
        )
        >
        [2] =Array
        (
        [0] =Leamore Windows Ltd
        [1] =55339883351141 7
        [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] =92058920521053 8
        >
        [2] =1
        )
        >
        [1] =Array
        (
        [0] =Leamore Windows Ltd
        >
        [1] =55339883351141 7
        [2] =22
        )
        >
        )
        >
        Hi,
        >>
        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.

        Comment

        • craig.keightley@gmail.com

          #5
          Re: Group an array

          On Jan 30, 12:31 pm, "strawberry " <zac.ca...@gmai l.comwrote:
          On 30 Jan, 10:56, Curtis <dyers...@veriz on.netwrote:
          >
          >
          >
          >
          >
          On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
          >
          <since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
          craig.keight... @gmail.com wrote:
          >
          >i have the following array:
          >
          >Array
          >(
          > [0] =Array
          > (
          > [0] =Leamore Windows Ltd
          > [1] =55339883351141 7
          > [2] =20
          > )
          >
          > [1] =Array
          > (
          > [0] =HRPC
          > [1] =92058920521053 8
          > [2] =1
          > )
          >
          > [2] =Array
          > (
          > [0] =Leamore Windows Ltd
          > [1] =55339883351141 7
          > [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] =92058920521053 8
          >
          > [2] =1
          > )
          >
          > [1] =Array
          > (
          > [0] =Leamore Windows Ltd
          >
          > [1] =55339883351141 7
          > [2] =22
          > )
          >
          >)
          >
          Hi,
          >>
          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.

          Comment

          • Captain Paralytic

            #6
            Re: Group an array

            On 31 Jan, 08:49, craig.keight... @gmail.com wrote:
            On Jan 30, 12:31 pm, "strawberry " <zac.ca...@gmai l.comwrote:
            >
            >
            >
            >
            >
            On 30 Jan, 10:56, Curtis <dyers...@veriz on.netwrote:
            >
            On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
            >
            <since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
            craig.keight... @gmail.com wrote:
            >
            i have the following array:
            >
            Array
            (
            [0] =Array
            (
            [0] =Leamore Windows Ltd
            [1] =55339883351141 7
            [2] =20
            )
            >
            [1] =Array
            (
            [0] =HRPC
            [1] =92058920521053 8
            [2] =1
            )
            >
            [2] =Array
            (
            [0] =Leamore Windows Ltd
            [1] =55339883351141 7
            [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] =92058920521053 8
            >
            [2] =1
            )
            >
            [1] =Array
            (
            [0] =Leamore Windows Ltd
            >
            [1] =55339883351141 7
            [2] =22
            )
            >
            )
            >
            Hi,
            >>
            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!

            Comment

            • craig.keightley@gmail.com

              #7
              Re: Group an array

              On Jan 31, 9:53 am, "Captain Paralytic" <paul_laut...@y ahoo.com>
              wrote:
              On 31 Jan, 08:49, craig.keight... @gmail.com wrote:
              >
              >
              >
              >
              >
              On Jan 30, 12:31 pm, "strawberry " <zac.ca...@gmai l.comwrote:
              >
              On 30 Jan, 10:56, Curtis <dyers...@veriz on.netwrote:
              >
              On Mon, 29 Jan 2007 06:07:48 -0800, Erwin Moller
              >
              <since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
              craig.keight... @gmail.com wrote:
              >
              >i have the following array:
              >
              >Array
              >(
              > [0] =Array
              > (
              > [0] =Leamore Windows Ltd
              > [1] =55339883351141 7
              > [2] =20
              > )
              >
              > [1] =Array
              > (
              > [0] =HRPC
              > [1] =92058920521053 8
              > [2] =1
              > )
              >
              > [2] =Array
              > (
              > [0] =Leamore Windows Ltd
              > [1] =55339883351141 7
              > [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] =92058920521053 8
              >
              > [2] =1
              > )
              >
              > [1] =Array
              > (
              > [0] =Leamore Windows Ltd
              >
              > [1] =55339883351141 7
              > [2] =22
              > )
              >
              >)
              >
              Hi,
              >>
              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

              Comment

              Working...