Php Foreach循环解释
有人能解释一下这个代码结构吗Php Foreach循环解释,php,foreach,Php,Foreach,有人能解释一下这个代码结构吗 // Remove all fields and field instances. foreach (field_info_instances('node', 'windfarm') as $field_name => $instance) { field_delete_field($field_name); field_delete_instance($instance); } 特别是作为$field\u name=>$inst
// Remove all fields and field instances.
foreach (field_info_instances('node', 'windfarm') as $field_name => $instance) {
field_delete_field($field_name);
field_delete_instance($instance);
}
特别是作为$field\u name=>$instance
。我的理解是field_info_instances()返回一个数组,$field_name
是循环中使用的项。但是,=>$instance
部分是什么
到目前为止,我只见过这种类型的foreach:
foreach ($array as $item) {
statement
}
你可以这样看:
foreach ($array as $key => $value) {}
因此,在这样一个结构的数组中:
$arr=['some','values','to','populate','the','array']代码>
$key
将是数组索引,0,1,2,3,4,5
$value
将是some,value,to,populate,the,array
field\u info\u实例('node','windfarm')
返回一个数组,然后以$field\u name
作为索引,以$instance
作为每个数组元素的值,在该数组中进行迭代