View Single Post
Old 06-02-2008, 04:47 PM   #4 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

According to his notation he is getting separate, which is a bit odd.

After alittle more thought i came up with this convoluted script (providing you are getting 7 separate arrays):

WARNING: hackish code, it may blind you! YOU HAVE BEEN WARNED!

PHP Code:
$arr1 = array ( => 1=> );
$arr2 = array ( => 2=> 19 );
$arr3 = array ( => 4=> 18 );
$arr4 = array ( => 5=> );
$arr5 = array ( => 6=> );
$arr6 = array ( => 7=> 19 );
$arr7 = array ( => 9=> );

for(
$i=0$i 7;$i++)
{
    eval(
'${"mUnit" . $arr'.($i+1).'[0]} = $arr'.($i+1).'[1];');
}



echo 
'Unit1: '$mUnit1'<br />',
     
'Unit2: '$mUnit2'<br />',
     
'Unit4: '$mUnit4'<br />',
     
'Unit5: '$mUnit5'<br />',
     
'Unit6: '$mUnit6'<br />',
     
'Unit7: '$mUnit7'<br />',
     
'Unit9: '$mUnit9
outputs:
Unit1: 4
Unit2: 19
Unit4: 18
Unit5: 5
Unit6: 7
Unit7: 19
Unit9: 6

there are a few things about this however:
1. eval is slow and can be a security risk
2. you are limited to 7 arrays unless you manually change the loop
3. its barely readable
4. i have a reasonably large headache now

I think the better way is to re-think how you retrieve your data (assuming this is how you are retrieving it currently, i apologise if i have misunderstood).
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
Dave (06-02-2008)