목록을 높은 값에서 낮은 값으로 정렬하고 싶습니다. 그 산출물의 가치는 여론 조사에서 나온 것이다. optionOne : 11 : optionTwo : 5 :PHP로 목록을 값으로 정렬하는 방법
내가 일을 시도
function votingScore($item, $itemvoted) {
$hector=count($itemvoted);$totalvotes=0;$in=0;$stepstr='';
$totalvotes=SumArray($itemvoted);
$in=0;
if ($totalvotes==0) { $totalvotes=0.0001; }
while ($in<$hector) {
$stepstr=$stepstr.'<li>'.stripslashes($item[$in]).(int)(($itemvoted[$in]/$totalvotes)*100).'% ';
$stepstr=$stepstr.'</li>';
$in++;
}
return '<ul>'.$stepstr.'</ul>'; }
투표는 다음과 같이 lokes 텍스트 파일에 저장됩니다 : 여기
목록을 생성하는 코드입니다 다음arsort($stepstr);
foreach ($stepstr as $key => $val) {
echo "stepstr[" . $key . "] = " . $val . "\n"; }
FIX :
내가 제대로 코드를 이해한다면function votingScore($item, $itemvoted) {
$combineSort = array_multisort($itemvoted, SORT_DESC, $item, SORT_DESC); //added this line and got it to work
$hector=count($itemvoted);$totalvotes=0;$in=0;$stepstr='';
http://www.php.net/manual/array.sorting.php –
@ jan1337z이 (가) 어서 오세요! 나는이 기능이 몇 가지 중요한 것을 보여줄 책임이 있다고 생각합니다 ... 물건. 물건은 뭐든간에. 분명히 중요한 것입니다. 그것은 가능해야합니다. 아마? 나는 모른다. – matewka
@ jan1337z 더 좋아하십니까? – florisvl