NLCJ Posted June 20, 2011 Share Posted June 20, 2011 Hello, I've got multiple variables that are all an array. I set them up like: $round1 = ...; $round2 = ...; $round3 = ...; All the way up to 10, now I created this: $numbers = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); $rounds = array("round1", "round2", "round3", "round4", "round5", "round6", "round7", "round8", "round9", "round10"); for($i = 1; $i < 11; $i++) { $newi = str_replace($numbers, $rounds, $i); echo $newi."<br />"; } Sadly this is only working partially, the output is: round1 round2 round3 round4 round5 round6 round7 round8 round9 roundround10 Does anybody know why? If I make it "$i = 0;" the result is: roundroundroundroundroundroundroundroundroundround10 roundroundroundroundroundroundroundroundround10 roundroundroundroundroundroundroundround10 roundroundroundroundroundroundround10 roundroundroundroundroundround10 roundroundroundroundround10 roundroundroundround10 roundroundround10 roundround10 round10 I'm kinda stuck here. Is it because I'm trying to replace numbers? Regards, Chris Quote Link to comment https://forums.phpfreaks.com/topic/239919-replacing-numbers/ Share on other sites More sharing options...
AbraCadaver Posted June 20, 2011 Share Posted June 20, 2011 You want to replace the numbers with the rounds in what string of text? Quote Link to comment https://forums.phpfreaks.com/topic/239919-replacing-numbers/#findComment-1232404 Share on other sites More sharing options...
NLCJ Posted June 20, 2011 Author Share Posted June 20, 2011 I've fixed it another way, saving me a lot of other codes by combining some functions. But still, I'm wondering how this can fail. All I want is to use a variable, for example (it doesn't work): $currentround = $round.$i; The 'currentround' is depending on the $i, and I want to add the $i to the variablestring (lol?). I hope you get what I mean... Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/239919-replacing-numbers/#findComment-1232409 Share on other sites More sharing options...
AbraCadaver Posted June 20, 2011 Share Posted June 20, 2011 Whatever you are trying to do this is probably not the correct way, but in case I am wrong, this works fine: $round = 'round'; for($i=1; $i<11; $i++) { $currentround = $round.$i; echo "$currentround\n"; } round1 round2 round3 round4 round5 round6 round7 round8 round9 round10 Quote Link to comment https://forums.phpfreaks.com/topic/239919-replacing-numbers/#findComment-1232412 Share on other sites More sharing options...
NLCJ Posted June 20, 2011 Author Share Posted June 20, 2011 Ah well, I guess I made a typo a few hours ago? Thanks for explaining, glad to know I had the right thoughts. Regards, Chris Quote Link to comment https://forums.phpfreaks.com/topic/239919-replacing-numbers/#findComment-1232424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.