[thelist] PHP Challenge
email
email at timburgan.com
Thu Nov 24 00:21:29 CST 2005
Hello,
I'm wanting to interleave the characters of two strings to form one string.
For example:
String1 - FOO
String2 - evolt
Interleaved(String1, String2) = FeOvOolt
But, not limited to just two strings.
For example:
String1 - FOO
String2 - evolt
String3 - 1234
Interleaved(Interleaved(String1, String2), String3) = F1e2O3v4O5o6l7t8
I've made each "string" into its own array. ( e.g. array('F','O','O') )
I just can't get my head around it. Does anyone have any ideas?
Here's my code:
$parts = array($string1,$string2,$string3);
for ( $i = 0; $i < sizeof($parts); $i++ )
{
if ( $i % 2 == 0 )
{
for ( $j = 0; $j < sizeof($parts[$i])-1; $j++ )
{
$interleaved.= $parts[$i][$j];
}
}
else
{
for ( $j = 0; $j < sizeof($parts[$i])-1; $j++ )
{
$interleaved.= $parts[$i][$j];
}
}
}
echo $interleaved
More information about the thelist
mailing list