I am using array_map
function in my php application. I defined the array_map function like this.
$ratingID = $this->db->insert_id(); $rated_item_array = array_map(function ($a) { return $a + array('RatingID' => $ratingID); }, $rated_item_array);
Php notice comes
A PHP Error was encountered Severity: Notice Message: Undefined variable: ratingID
When i print the $ratingID
. i prints the value correctly , so $ratingID is defined. Why it is undfined in array_map
function? My $rated_item_array
is
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 ) )
Undefined variable: the variable's definition is not found in the project files, configured include paths, or among the PHP predefined variables. Variable might have not been defined: there are one or more paths to reach the line with the variable usage without defining it.
The array_map() function sends each value of an array to a user-made function, and returns an array with new values, given by the user-made function. Tip: You can assign one array to the function, or as many as you like.
The Ds\Map::map() function of the Map class in PHP is used to apply a callback function to a Map object. This returns the result of applying the callback function to each value present on the map.
$rated_item_array = array_map( function ($a) use ($ratingID){ return $a + array('RatingID' => $ratingID ); }, $rated_item_array );
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