oracle259 Posted October 20, 2006 Share Posted October 20, 2006 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] Link to comment https://forums.phpfreaks.com/topic/24514-combining-strings/ Share on other sites More sharing options...
akitchin Posted October 20, 2006 Share Posted October 20, 2006 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] Link to comment https://forums.phpfreaks.com/topic/24514-combining-strings/#findComment-111684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.