PART 1: I need to create a loop for a set of array variables
for ($cnt=1; $cnt<=$qty; $cnt++) {
$firstvar.$cnt['Code'] = '02';
$secondvar.$cnt['Type'] = $somevar;
$thirdvar.$cnt['Code'] = 'IN';
}
// with a result of
$firstvar1['Code'] = '02';
$secondvar1['Type'] = $somevar;
$thirdvar1['Code'] = 'IN';
$firstvar2['Code'] = '02';
$secondvar2['Type'] = $somevar;
$thirdvar2['Code'] = 'IN';
//etc.
However, the parsing of the $cnt variable seems to be conflicting with the array.
PART 2: I then need to create an array of variables like so:
$lastvar['Thing'] = array( $thirdvar1, $thirdvar2, ... $thirdvar.$qty );
Here, creating a simple string using a for loop and placing it in the array doesn’t work.
THANKS!
PART 1:
$firstvar.$cnt['Code']should be${"firstvar$cnt"}['Code'](or${'firstvar'.$cnt}['Code']).PART 2:
PART 3: (mine!)
Put everything in the same loop:
}
Keep in mind that this code would be cleaner if you use arrays instead of variables names concatenation.