Variable from array in loop

Hi everyone

I am looking to make my first php script and need some assistance. Here is my code

[php]
for ($ix = 1; $ix < count($records); $ix++) {
$tmp = $records[$ix];

	preg_match('/notimportant/', $tmp, $variable1);
	preg_match('/notimportant/', $tmp, $variable2);
	preg_match('/notimportant/', $tmp, $variable3);
	
	$r[1] = Array(
		'v1' => $variable1[1],
		'v2' => $variable2[1],
                    'v3' => $variable3[1]);

	print_r ($r);
}

[/php]

At the moment the variables are being put into an array and dumped on screen. What I would like to do is continue using the variables further in the script. I know this isn’t right but something along the lines of

[php]
$first = $variable1[1]
$first2 = $variable1[2]
$first3 = $variable1[3]

second = $variable2[1]
second2 = $variable2[2]
second3 = $variable2[3]

third = $variable3[1]
third2 = $variable3[2]
third3 = $variable3[3]
[/php]

I hope you understand what I mean and can assist.

Thankyou

Something like this?

[php]for($i=1; $i<=3; $i++){
${‘first’.($i==1?’’:$i)} = $variable1[$i];
${‘second’.($i==1?’’:$i)} = $variable2[$i];
${‘third’.($i==1?’’:$i)} = $variable3[$i];
}[/php]

This will set variables: $first, $first2, $first3, $second, $second2, …

Sponsor our Newsletter | Privacy Policy | Terms of Service