dqdz6464 2013-02-07 02:06
浏览 11
已采纳

根据爆炸项排序PHP数组

Completely new to PHP

I need to sort an array that was read in from a text file, line by line

$data = fgets($fileHandle);

Each $data contains 3 fields, which where exploded with

$otherData = explode(',',$data)

I need to sort the entire array ($data), by the first item in explode so it would be otherData[0];

from smallest to biggest, the firs item in explode is a number

how do i do this?

some research on google hasn't gotten me very far, any help is appreciated

  • 写回答

1条回答 默认 最新

  • duanjia3187 2013-02-07 02:10
    关注

    you can take the column you want to sort as the key of the array. then sort it with ksort

    $data = array();
    while($dataLine = fgets($fileHandle))
    {
        list($item1, $item2, $item3) = explode(',', $dataLine, 3);
        $data[$item1] = $item3;
    }
    ksort($data);
    print_r($data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答