Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2009, 02:52 PM   PM User | #1
shaneog
New to the CF scene

 
Join Date: Jan 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
shaneog is an unknown quantity at this point
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..
shaneog is offline   Reply With Quote
Old 01-07-2009, 03:43 PM   PM User | #2
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Something like this?

http://us3.php.net/manual/en/functio...unt-values.php
masterofollies is offline   Reply With Quote
Old 01-07-2009, 04:13 PM   PM User | #3
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
I believe array_chunk() is the PHP function that you want to use.

http://us3.php.net/manual/en/function.array-chunk.php
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Tags
array, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:47 AM.


Advertisement
Log in to turn off these ads.