I'm reading this format data from excel file. then I convert it into array. Now I want to perform calculation. I tried many times but no success. thanks
example
L*M 100*200
L*H 100*300
0 1 2
UserData
Length 100 L
Width 200 W
Height 300 H
AdminData
L*W Result
L*H Result
W*H Result
Total TotalRest
Array result using print_r()
Array
(
[0] => Array
(
[0] => UserData
[1] =>
[2] =>
)
[1] => Array
(
[0] => Length
[1] => 100
[2] => L
)
[2] => Array
(
[0] => Width
[1] => 200
[2] => W
)
[3] => Array
(
[0] => Height
开发者_StackOverflow [1] => 300
[2] => H
)
[4] => Array
(
[0] => AdminData
[1] =>
[2] =>
)
[5] => Array
(
[0] => L*M
[1] =>
[2] =>
)
[6] => Array
(
[0] => L*H
[1] =>
[2] =>
)
[7] => Array
(
[0] => W*H
[1] =>
[2] =>
)
[8] => Array
(
[0] => Total
[1] =>
[2] =>
)
)
Array function
$arrResult = array();
/////////////Open the csv file which contains data//////////////
$handle = fopen("data.csv", "r");
if( $handle ) {
///////Put the data in an array///////////
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$arrResult[] = $data;
}
fclose($handle);
}
$var = array(
array('UserData'),
array('Length', 100, 'L'),
array('Width', 200, 'W'),
array('Height', 300, 'H'),
array('AdminData'),
array('L*W'),
array('L*H'),
array('W*H'),
array('Total')
);
echo "<pre>";
print_r($var);
echo "</pre>";
$var[5][1] = $var[1][1]*$var[2][1];
$var[6][1] = $var[1][1]*$var[3][1];
$var[7][1] = $var[3][1]*$var[2][1];
echo "<pre>";
print_r($var);
echo "</pre>";
精彩评论