如何在php中的多维数组中插入值?我需要使用while循环向数组中添加越来越多的行。
这是我的代码:
$size=10;
$p=0;
while($p<$size)
{
$myarray = array(
array("number"=>$data[$p],"data"=>$kkk[1],"status"=>"A"),
array("number"=>$data[$p],"data"=>$kkk[1],"status"=>"A"));
// Each time the loop executes, I need to add more array to myarray.
$p++;
}
答案 0 :(得分:16)
$size = 10;
$p = 0;
$myarray = array();
while($p < $size) {
$myarray[] = array("number" => $data[$p], "data" => $kkk[1], "status" => "A");
$p++;
}
答案 1 :(得分:3)
$my_array = array()
foreach (range($p, $size-1) as $key) {
array_push($my_array, array(
"number" => $data[$key],
"data" => $kkk[1],
"status" => "A",
));
}
答案 2 :(得分:0)
$arr = new Array();
while($p<$size){
$arr[$p]["number"] = $data[$p];
$arr[$p]["data"] = $kkk[1];
$arr[$p]["status"] = "A";
$p++;
}