Ask how to add elements to a two-dimensional array. & Lt ;? Php & nbsp; while (mysql_fetch_array) {& nbsp; & nbsp; & nbs ask to add elements to a two-dimensional array.
while(mysql_fetch_array){
$arr[$key][] = array("value"=>$value);
if($somecondition){
foreach($arr as $k => $v){
$arr[$k][] = array("value"=>"");
}
}
}
?>
In this case, create a two-dimensional array and add elements cyclically, but when a condition $ somecondition occurs, add an element with null value to each $ key in the array.
After adding the element, we can see that all the added null elements are at the beginning of the array. why?
How can I add them correctly. Two-dimensional array PHP
------ Solution --------------------
If no key name is specified for the given value, the current maximum integer index value is used, and the new key name is the value plus one. If the specified key name already has a value, the value will be overwritten.
------ Solution --------------------
The idea should be like this.
While (mysql_fetch_array ){
If ($ somecondition) {// if the gap is too large
$ Arr [$ key] [] = array ("value" => ""); // inserts a null value. if there is more than one value, use the for loop.
}
$ Arr [$ key] [] = array ("value" => $ value); // add data
}