Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
对 PHP 完全陌生
我需要对从文本文件中读取的数组逐行进行排序
$data = fgets($fileHandle);
每个 $data 包含 3 个字段,其中爆炸
$otherData = explode(',',$data)
我需要通过爆炸中的第一项对整个数组($data)进行排序,因此它将是 otherData[0];
从小到大,explode 中的第一项是数字
我该怎么做呢?
对谷歌的一些研究并没有让我走得太远,感谢任何帮助
您可以将要排序的列作为数组的键。然后对其进行排序ksort
ksort
$data = array(); while($dataLine = fgets($fileHandle)) { list($item1, $item2, $item3) = explode(',', $dataLine, 3); $data[$item1] = $item3; } ksort($data); print_r($data);