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",
));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With