我想通过snmpwalk从有线调制解调器读取一些上游数据。 (us channel channel,us channel freq / MHz /,us channel width / MHz /).
在Docsis 3.0模式中,我得到至少两个"记录" (但最多8个),就像这个例子:
4; 52; 6.4 // first upstream channel record
3; 45; 6.4 // second upstream channel record
所以我不知道收到的"记录的数量"我想用多维数组解决这个问题并动态添加项目。
当我收到所有"记录",然后我想按照我们的频道ID'对它们进行排序,因此结果应如下所示:
3; 45; 6.4
4; 52; 6.4
我知道这可以通过字符串连接解决,但我更喜欢数组。
答案 0 :(得分:1)
根据给出的信息,我写了这个答案
使用foreach获取数组
foreach ($data as $key => $row) {
$channel_array['channel_id'] = $row['channel_id'];
$channel_array['channel_freq'] = $row['channel_freq'];
$channel_array['channel_width'] = $row['channel_width'];
}
你的数组应该是这样的
Array = (
[0] = array (
[channel_id] => 4
[channel_freq] => 52
[channel_width] => 6.4
)
[1] = array (
[channel_id] => 3
[channel_freq] => 45
[channel_width] => 6.4
)
如果要按channel_id排序,请首先创建一个单独的channel_id数组:
foreach ($channel_array as $channel) {
$channel_ids[] = $channel['channel_id'];
}
然后使用
array_multisort($channel_ids, SORT_ASC, $channel_array);