0

How can I add $i to var $pitch in below code. Result should be

$pitch1, $pitch2, $pitch3, etc.

$i = '1';
foreach($pitches as $pitch) {
    if($pitch->option_name == 'agent_pitch_'.$i) $pitch.$i = $pitch->option_value ;
    $i++;
}
jtermaat
  • 31
  • 7
  • 1
    Is [this](https://3v4l.org/fYlnb) what you are looking for? `$i = 1; ${'foo'.$i} = 'bar'; echo $foo1;`. Update: judging by the dup, yeah xD – FirstOne Nov 20 '17 at 19:26
  • YES! thanks a lot. For Chris85: if somebody has posted my thread before then he is very good. Just coded this part in the last 30min as new code. – jtermaat Nov 20 '17 at 19:33
  • @jtermaat The dup isn't what you are trying to do? – chris85 Nov 20 '17 at 19:33
  • 1
    New code doesn't mean unique code. It's very unlikely that you'll face an unseen problem / error. A duplicate doesn't have to be an exact copy of the problem. BTW, that 'thread' is from 2013... – FirstOne Nov 20 '17 at 19:34

0 Answers0