with keys array_walk array_map array php arrays array-map

keys - php array_walk



Error de PHP ¿Por qué es "variable undefined" dentro de array_map? (1)

$rated_item_array = array_map( function ($a) use ($ratingID){ return $a + array(''RatingID'' => $ratingID ); }, $rated_item_array );

Estoy usando la función array_map en mi aplicación php. Definí la función array_map de esta manera.

$ratingID = $this->db->insert_id(); $rated_item_array = array_map(function ($a) { return $a + array(''RatingID'' => $ratingID); }, $rated_item_array);

Aviso de php viene

A PHP Error was encountered Severity: Notice Message: Undefined variable: ratingID

Cuando $ratingID el $ratingID . Imprime el valor correctamente, por lo que se define $ ratingID. ¿Por qué no está definido en la función array_map ? Mi $rated_item_array es

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 ) )