Page 1 of 1

array function?

Posted: Sun Nov 07, 2004 4:20 am
by deras
i have two variables ($sums1, $sums2) which have nine values in them(seperated by ":") 8:2:12:23:12:23:33:32:23

i wanted to get each of those values seperated into nine seperate variables

i tried this

Code: Select all

for ($i=0; $i<=8; $i++)
{
$sums1[$i]=split(":",$sums1);
$sums2[$i]=split(":",$sums2);
 }
but that did not seem to work. any ideas on how to do this properly?

Posted: Sun Nov 07, 2004 4:50 am
by markl999
A few ways to do this, here's one:

Code: Select all

<?php
$sums1 = '8:2:12:23:12:23:33:32:23';
$sums2 = '7:3:12:3:17:20:33:11:33';
for($x=1;$x<3;$x++){
  $sum = 'sums'.$x;
  $sum_array = 'sums'.$x.'_array';
  foreach(explode(':', $$sum) as $val){
    ${$sum_array}[] = $val;
  }
}
echo '<pre>';
var_dump($sums1_array);
var_dump($sums2_array);
echo '</pre>';
?>

Posted: Sun Nov 07, 2004 7:26 am
by deras
thanks...