Jump to content


Photo

combining strings


  • Please log in to reply
1 reply to this topic

#1 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 20 October 2006 - 05:49 AM

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....

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



#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 20 October 2006 - 06:00 AM

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:

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users