0
Short data of .txt file using Php. Brief description given below. Need help pls
I have one file one.txt which contains players scores like Virat = 70 Dhoni = 50 Rahane = 80* Rohit = 150* Dhawan = 60 Hardik = 30 * Shows that player is not out. Now i want highest score for both not out and out. In output i want Highest not out score - 150 And Highest out score - 70. How can i do ... I have tried myself but not getting right answer. Anyone can help me please... I don't want code any one can suggest me algorithm too... Thank you
11 Respuestas
+ 1
Use 3 variables
- First for read
- Second to assign not out if it is bigger than saved not out.
- Third to assign out if it is bigger than saved out.
+ 1
$notout=0;
$out=0;
$read=0;
READ until eof
if $read "is not out" and $read>$notout then $notout=$read
else if $read "is out" and $read>$out then $out=$read
This is some type of pseudocode so you must to "translate" to PHP. I hope it help you ;-)
+ 1
i tried something very related to this but didn't get output... anywy I'll try again
0
I will be waiting for your code
0
<?php
$out = [];
$notout = [];
$array_notout = [];
$array_out=[];
$handle = fopen("one.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$len = strlen($line);
$string = $line;
$var = substr(trim($string), -1);
if($var == '*'){
array_push($notout, $line);
} else {
array_push($out, $line);
}
}
foreach ($notout as $value){
$exp = explode('=',$value);
$t = str_replace( '*', '', $exp[1] );
//echo $t;
$array_notout[$exp[0]] = $t;
}
//print_r($array_notout);
foreach ($out as $val){
$exps = explode('=',$val);
$array_out[$exps[0]] = $exps[1];
}
sort($array_notout);
sort($array_out);
//print_r($array_notout);
echo "<br>";
echo "The Highest score is of out is ".$array_out[0];
echo "The Highest score is of Not out is ".$array_notout[0];
fclose($handle);
} else {
// error opening the file.
}
?>
0
not working for * array
0
But is it working?
0
ya i m getting right answer for OUT... but for not out I'll have to look on sorting
0
ok but I think you are using more code than you must
0
i don't know but i just followed simple algorithm...
0
I think you dont need arrays because you wrote finally you only need one value per out and one per not out