Home  >  Article  >  Backend Development  >  下面的数组小弟我该怎么生成~

下面的数组小弟我该怎么生成~

WBOY
WBOYOriginal
2016-06-13 12:49:08721browse

求教: 下面的数组我该如何生成~~~~~~~~~~~~~~~!
$traffic_type $in_bytes
18            2011110
19            1999110
18            1923832
19            2893823

其中$traffic_type不只有18和19,种类数不确定,
上面有很多行那样的数据。我想生成如下数组:
{
{18:{{"value"=>"2011110"},{"value"=>"1923832"}}
{19:{{"value"=>"1999110"},{"value"=>"2893823"}} 
}

上面数组可能写得不对,不过大概就是这么个意思。

在while循环里面应该怎么生成上面的数组?

whlie(){<br />
$arr_data_by_prote.$traffic_type[] = array("value"=>$in_bytes);<br />
$arr.$traffic_type[] = array("value"=>$in_bytes);<br />
}

这样吗? 不过这样报错了。

PHP 多维数组
------解决方案--------------------
whlie($row=...){

  $arr[$row['traffic_type']][] = array("value"=>$row['in_bytes']);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn