Passing Variable into Callback PHP -


i have function below called , passed array. pass field (or key) name reusable. when try pass $field in callback below error $field not defined. if use literal, works great.

function array_map_recursive($array,$field) {         $sum = 0;         foreach ($array $key => $value) {            foreach ($value $key2 => $value2) {                $sum += array_sum(array_map(function($item){return $item[$field];},$value[$key2]));            }         }         return $sum; } 

called:

number_format(array_map_recursive($dept_catg_grp_descs,"total_ty_yest_sales")) 

function ($item) use ($field) {return $item[$field];} 

this "imports" $field variable function.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -