SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 6th, 2002, 08:28 PM
omar omar is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 18 omar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Splitting an array into another multi-array

Splitting an array into another multi-array


Hi guys,
Lets say that I have an array with 11 elements
like the diagram of the array below:

$full_array = array(
['1'] => 'abc',
['2'] => 'cde',
['3'] => 'ghf',
['4'] => '12g',
['5'] => 'gh5',
['6'] => '878',
['7'] => '14y',
['8'] => 'd56',
['9'] => 'hj6',
['10'] => '9h7',
['11'] => 'o89'
);

now with the array above I would like to now
split it up and store it in another array,
"an array of arrays"
but there should be "no more than 3 elements"
in each array (sub-array) when it's split up,
example below:

$split_array = array(

[0] => array(['1'] => 'abc',
['2'] => 'cde',
['3'] => 'ghf')

[1] => array(['4'] => '12g',
['5'] => 'gh5',
['6'] => '878')

[2] => array(['7'] => '14y',
['8'] => 'd56',
['9'] => 'hj6')

[3] => array(['10'] => '9h7',
['11'] => 'o89')

);


What is the easiest wway to accomplish the above
task.

An example would be nice!

Thank you!

Reply With Quote
  #2  
Old November 7th, 2002, 08:11 AM
Robo Robo is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 8 Robo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP Code:
for (0$j size($full_array) / 3$j 3) {
    
$index 0;
    for (
$i $j$i $j 3$i++) {
        
$split_array[$index][$i] = $full_array[$i];
    }
    
$index++;
}

print_r($split_array); 


I haven't tested this code, so there might be an off-by-one error, but the logic should be correct.

Last edited by Robo : November 7th, 2002 at 08:17 AM.

Reply With Quote
  #3  
Old November 7th, 2002, 09:04 AM
omar omar is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 18 omar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks

thanks i'll give it a try

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Splitting an array into another multi-array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway