coollog Posted June 11, 2009 Share Posted June 11, 2009 I was making this simple high score list, and I came across a problem, here's my code: <img src="loadingbar.png"/><br/> <center><h2>High Scores List</h2></center> <? $dir=dir("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server"); $arr=array(); while (($file = $dir->read()) !== false){ $path_info = pathinfo("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\".$file); if($path_info['extension']=='acc'){ $ini=parse_ini_file('C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\'.$file); if(isset($_ini['score']) and (real)($ini['score'])>1000){ $arr[basename($file,'.acc')]=$ini['score']; } } } asort($arr,SORT_NUMERIC); $n=1; print_r($arr); foreach($arr as $key=>$val){ echo '#'.$n.' '.$key.' ('.$val.')<br/>'; $n++; } ?> This won't have any values go through the check of if(isset($_ini['score']) and (real)($ini['score'])>1000) But when I change the code to this, there are errors of unknown indexes of score, but it still displays the right ones: <img src="loadingbar.png"/><br/> <center><h2>High Scores List</h2></center> <? $dir=dir("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server"); $arr=array(); while (($file = $dir->read()) !== false){ $path_info = pathinfo("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\".$file); if($path_info['extension']=='acc'){ $ini=parse_ini_file('C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\'.$file); if((real)($ini['score'])>1000){ $arr[basename($file,'.acc')]=$ini['score']; } } } asort($arr,SORT_NUMERIC); $n=1; print_r($arr); foreach($arr as $key=>$val){ echo '#'.$n.' '.$key.' ('.$val.')<br/>'; $n++; } ?> Do you know what's wrong? And if you could optimize my code, that would be awesome! Link to comment https://forums.phpfreaks.com/topic/161751-simple-high-score-list-something-seems-wrong/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.