foreach ($facility _list[' data ') as $facility) {
Processing statements
}
The first format iterates through the given array of Array_expression_r_r. In each loop, the value of the current cell is assigned to the $value and the pointer inside the array is moved forward one step (so the next cell in the next loop will be taken).
The second format does the same thing, except that the key value of the current cell is assigned to the variable $key in each loop.
Note: When foreach starts executing, the pointer inside the array automatically points to the first cell. This means that you do not need to call Reset () before the Foreach loop.
Note: Also note that foreach is manipulating a copy of the specified array, not the array itself. So even with each () construct, the original array pointer does not change, and the value of the array cell is unaffected.
Note: foreach does not support the ability to suppress error messages with "@".
Suppose the requested data format:
$facility _list variable values are:
Array (1) {["Data"]=> Array (3) {[0]=> Array (4) {["facility_id"]=> string (1) "1" ["Facility_name"]=> string (9 "Jiaxing Warehouse" ["Schedule_mode"]=> string "manual_schedule_auto_shipping" ["Facility_type"]=> string (1) "1"} [1]= > Array (4) {["facility_id"]=> string (1) "2" ["Facility_name"]=> string (9) "Guangzhou warehouse" ["Schedule_mode"]=> string ( "Manual_schedule_auto_shipping" ["Facility_type"]=> string (1) "1"}}}
Here is an array of arrays (1), so we need to get the data inside, we need to go to the value in this array data point,
$facility _list[' data ') variable value is:
Array (3) {[0]=> Array (4) {["facility_id"]=> string (1) "1" ["Facility_name"]=> string (9) "Jiaxing warehouse" ["Schedule_mode" ]=> string "manual_schedule_auto_shipping" ["Facility_type"]=> string (1) "1"} [1]=> Array (4) {["Facility_ ID "]=> string (1)" 2 "[" Facility_name "]=> string (9)" Guangzhou warehouse "[" Schedule_mode "]=> string" Manual_schedule_auto _shipping "[" Facility_type "]=> string (1)" 1 "}}
The following array is obtained by this statement, which is equivalent to entering an internal array from an external array, containing an array, and iterating over each value on the inner array, for example:
$facility [' facility_id '] variable values are:
String (1) "1"
Example:
$facility _list=$this->common->getfacilitylist (); $facility _id=$this->getinput (' facility_id '); if(isset($facility _id)) { $cond[' facility_id '] =$facility _id; foreach($facility _list[' Data '] as $facility){ if($facility[' facility_id ']==$facility _id){ $cond[' Facility_type ']=$facility[' Facility_type ']; } } } Else { $cond[' facility_id '] =$facility _list[' Data '] [0] [' facility_id ']; $cond[' facility_type '] =$facility _list[' Data '] [0] [' Facility_type ']; }
PHP foreach Traversal