How can I insert values into a multidimensional array in php? I need to add more and more rows to array using a while loop.
Here is my code:
$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++;
}
$size = 10;
$p = 0;
$myarray = array();
while($p < $size) {
$myarray[] = array("number" => $data[$p], "data" => $kkk[1], "status" => "A");
$p++;
}
$my_array = array()
foreach (range($p, $size-1) as $key) {
array_push($my_array, array(
"number" => $data[$key],
"data" => $kkk[1],
"status" => "A",
));
}
$arr = new Array();
while($p<$size){
$arr[$p]["number"] = $data[$p];
$arr[$p]["data"] = $kkk[1];
$arr[$p]["status"] = "A";
$p++;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.