Jump to content

Archived

This topic is now archived and is closed to further replies.

oracle259

combining strings

Recommended Posts

How can i modify the code below to allow me better control the combination.

eg i select $combine = 1 gives $string3 = 1524334251
$combine = 2 gives $string3 = 125344213...
$combine = 3 gives $string3 = 123545....

[code]
<?php
$string1 = "12345";
$string2 = "54321";
$string3 = '';
for($i=0;$i<strlen($string1);$i++)
  $string3 .= $string1[$i] . $string2[$i];
echo $string3;
?>

[/code]

Share this post


Link to post
Share on other sites
well, $string1 is not an array, so $string1[$i] will not work.  to specify a particular character within a string, use curly braces after the variable, not square brackets:

[code]for($i=0;$i<strlen($string1);$i++)
  $string3 .= $string1{$i} . $string2{$i};[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.