Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I divide an array into multiple arrays?

    Hi there, I am trying to divide a single array into multiple arrays using a $variable. The $variable is the number of fields in my database table.

    For example, if $variable = 3...

    Array
    (
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => 9
    [9] => 10
    [10] => 11
    [11] => 12
    )

    Would become...

    Array[0]
    (
    [0] => 1
    [1] => 4
    [2] => 7
    [3] => 10
    )

    Array[1]
    (
    [0] => 2
    [1] => 5
    [2] => 8
    [3] => 11
    )

    Array[2]
    (
    [0] => 3
    [1] => 6
    [2] => 9
    [3] => 12
    )

    The array could either divided into a multi-dimensional array or 3 separate arrays, either would work.

    If someone knows of a way to do this would be of great help. Basically I am trying to create a search class that gathers all database table fields and row data then shows the results in a table. If someone has also done something similar please let me know!!!

    Thanks
    Last edited by shaneog; 01-07-2009 at 03:04 PM.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I believe array_chunk() is the PHP function that you want to use.

    http://us3.php.net/manual/en/function.array-chunk.php


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •