Forum Moderators: coopster

Message Too Old, No Replies

Splitting Array Values

         

itledi

3:17 pm on Dec 14, 2007 (gmt 0)

10+ Year Member



Imagine I have a line of couples waiting to get into a dance club. If this were an array, I would have three values. But what if I wanted to count people, and to force my couple array into a people array, while keeping their order in line in mind.

How can I turn this:
$couple=array("AB","CD","EF");

Into this:
$singles_good=array("A","B","C","D","E","F");

And NOT this:
$singles_bad=array(array("A","B"),array("C","D"),array("E","F"));

Something that would force:
$before=array("W","XY","Z");

Into:
$after_good=array("W","X","Y","Z");

And not:
$after_bad1=array("W",array("X","Y"),"Z");

Or:
$after_bad2=array("W","X","Z","Y");

d40sithui

4:30 pm on Dec 14, 2007 (gmt 0)

10+ Year Member



try this. im assuming the main array is already sorted.

<?
$newCouple = array();
for($i = 0; $i < sizeof($couple); $i++){

$thisCouple = $couple[$i];
$len = 0;

while($len < strlen($thisCouple)){
$thisPerson = substr($thisCouple, $len, 1);
if(!empty($thisPerson)){
$newCouple[] = $thisPerson;
}
$len++;
}
}
?>