Compare the CSV file of two, in the case of the same identifier, I want to make the calculation at a certain formula. And Always, I can't get The first row result.
My code (test.php)
<html>
<head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XTHML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="it_test_check_uesr_list_table.css" /></head>
<body>
<?php
$data = fopen("rate.csv", "r");
/* rate.csv
code,codename,data,.......
3668,A, 3325,+50(+1.53%),410518,A
3765,B, 606,+1(+0.17%),698118,B
7832,C, 2557,+10(+0.39%),567654,C
6460,D, 2048,-11(-0.53%),545238,D
*/
$baserate = fopen("baserate.csv", "r");
/* baserate.csv
code,data
7832,2312
3765,734
3668,3025
6460,2682
*/
if($baserate){
while ($baserate_line = fgets($baserate))
{
list($temp_code,$temp_data) = explode(",", rtrim($baserate_line));
$base_rate[] = (object)array('code' => $temp_code,
'data' => mb_convert_encoding($temp_data, "UTF-8", "auto"));
}
}
if($data){
while ($line = fgets($data))
{
list($temp_code,$temp_codename,$temp_data,$temp_comparison_previous_day,$temp_market_capitalization,$temp_market) = explode(",", rtrim($line));
for($i = 0; $i< count($base_rate); $i++)
{
if($temp_code == $base_rate[$i]->code)
{
//What I want (temp_data_index)
$temp_data_index = number_format($temp_data / $base_rate[$i]->data * 100,2);
}
}
$company[] = (object)array('code' => $temp_code,
'codename' => mb_convert_encoding($temp_codename, "UTF-8", "auto"),
'data' => mb_convert_encoding($temp_data, "UTF-8", "auto"),
'comparison_previous_day' => mb_convert_encoding($temp_comparison_previous_day, "UTF-8", "auto"),
'market_capitalization' => mb_convert_encoding($temp_market_capitalization, "UTF-8", "auto"),
'market' => mb_convert_encoding($temp_market, "UTF-8", "auto"),
'data_index' => mb_convert_encoding($temp_data_index, "UTF-8", "auto"));
}
}
// A(The first row ) Always don't work
for($i = 0; $i< count($company); $i++)
{
echo $company[$i]->codename." - ".$company[$i]->data_index."<br>";
}
?>
</body>
</html>
Result is
A -
B - 82.56
C - 82.56
D - 76.36
'A'(The first row in csv file) Doesn't work for loop.(There is same code, I checked var_dump) What's my problem?
$temp_data,$base_rate[$i]->data,$temp_data_index,mb_convert_encoding($temp_data_index, "UTF-8", "auto"),$company[$i]->data_indexwhen it's first created