That last post was a little messed up so I will try again...
$Array1="10:S MW/20:DHTS/10:D HCS/60:RN";
//
// Data stored in $Array1 is actually retreives from
// a MySQL database..
// there are 4 'groups' in that array.. containing 2 elements each
// the first 'group is '10' and 'S MW'
// the second group is '20' and DHTS etc..
// the first element is each group is ging to be a percentage
// .. the second part is a CODE that is going to be assigned
// the preceding percentage
// so the first group says S MW = 10%
//
// seperate the $Array1 into 'groups'
$Array2 = explode("/",$Array1);
for ($i=0; $i<count($Array2); $i++)
{
// seperate 'groups' into each element
$Array3[$i]=explode(":",$Array2[$i]);
}
$k=0;
while (each($Array3))
{
for ($t=0; $t<count($Array3[$k]); $t++)
{
echo "Array [$k][$t] : {$Array3[$k][$t]}<br>";
}
$k++;
}
That code displays this:
Array [0][0] : 10
Array [0][1] : S MW
Array [1][0] : 20
Array [1][1] : DHTS
Array [2][0] : 10
Array [2][1] : D HCS
Array [3][0] : 60
Array [3][1] : RN
Now, lets say there is a variable called $TOTAL.
$TOTAL = "40.25";
I want the 1st set of values in each 'group' in the $Array1 to be a percentage of $TOTAL and assigned that value to the second set in each group.
something like this..
using the formula to get the percentage
$Value2_from $ArrayGroup = $Value1_from_ArrayGroup *$TOTAL / 100
the first group from Array1 is '10: S MW'
so I want 10% of $TOTAL to be assinged to 'S MW'
S MW = 4.025
(10*40.25/100 = 4.025)
(10% of 40.25)
DHTS = 8.05
(20% of 40.25)
D HCS = 4.025
(10% of 40.25)
RN = 24.15
(60 % of 40.25)
so the display would looke like this
TOTAL = 40.25
S MW = 4.025
DHTS = 8.05
D HCS = 4.025
RN = 24.15
I am not really sure that make sence but I sure hope so..
Again, Thank you very much,
-Mystic