[英]PHP error. Why is “variable undefined” inside array_map?
I am using array_map
function in my php application. 我在我的php应用程序中使用
array_map
函数。 I defined the array_map function like this. 我像这样定义了array_map函数。
$ratingID = $this->db->insert_id();
$rated_item_array = array_map(function ($a) {
return $a + array('RatingID' => $ratingID);
}, $rated_item_array);
Php notice comes Php通知来了
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: ratingID
When i print the $ratingID
. 当我打印
$ratingID
。 i prints the value correctly , so $ratingID is defined. 我正确打印了值,因此定义了$ ratingID。 Why it is undfined in
array_map
function? 为什么在
array_map
函数中array_map
? My $rated_item_array
is 我的
$rated_item_array
是
Array
(
[0] => Array
(
[RatingFactorPreferenceID] => 1,
[PreferenceID] => 45,
[RatedValue] => 1,
[CreatedOn] => 1326790338,
[CreatedBy] => 25
)
[1] => Array
(
[RatingFactorPreferenceID] => 2,
[PreferenceID] => 45,
[RatedValue] => 1,
[CreatedOn] => 1326790338,
[CreatedBy] => 25
)
[2] => Array
(
[RatingFactorPreferenceID] => 3,
[PreferenceID] => 45,
[RatedValue] => 1,
[CreatedOn] => 1326790338,
[CreatedBy] => 25
)
)
$rated_item_array = array_map(
function ($a) use ($ratingID){
return $a + array('RatingID' => $ratingID );
},
$rated_item_array
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.