sw45acp Posted June 16, 2009 Share Posted June 16, 2009 How can a for loop be written to write out this sentence x number of times and only increment the number after $bla by one each time? ($bla1, $bla2, etc.). But keep in mind that $bla1 and $bla2 and so on are already variables in an early script. echo (function foobar($woof,$bla1) == $something) ? "laskjflasjf $bla1" : "<s>$bla1</s>"; echo (function foobar($woof,$bla2) == $something) ? "laskjflasjf $bla2" : "<s>$bla2</s>"; I was thinking something like this: for ($x = 1; $x<=3; $x++) { echo (function foobar($woof,$bla$x) == $something) ? "laskjflasjf $bla$x" : "<s>$bla$x</s>"; } but it doesnt work because the foobar() function only allows two variables, and I think because of the fact that $bla is alreay a variable. Any help would be appreciated Link to comment https://forums.phpfreaks.com/topic/162339-solved-a-for-loop-problem/ Share on other sites More sharing options...
Zane Posted June 16, 2009 Share Posted June 16, 2009 call $blah like this ${"bla" . $x} for ($x = 1; $x{ echo (function foobar($woof, ${"bla" . $x}) == $something) ? "laskjflasjf ${"bla" . $x}" : "${"bla" . $x}"; } Link to comment https://forums.phpfreaks.com/topic/162339-solved-a-for-loop-problem/#findComment-856873 Share on other sites More sharing options...
sw45acp Posted June 16, 2009 Author Share Posted June 16, 2009 Never knew that variables could be appending like that using {}. Thank you. Link to comment https://forums.phpfreaks.com/topic/162339-solved-a-for-loop-problem/#findComment-856879 Share on other sites More sharing options...
Zane Posted June 16, 2009 Share Posted June 16, 2009 Yes, it's called Variable Variables Link to comment https://forums.phpfreaks.com/topic/162339-solved-a-for-loop-problem/#findComment-856890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.