php - Filter multidimensional array on second level -


this question has answer here:

there lot of threads filtering, i'm google day long , can't work.

i have array, created thru mysqli query.

$cat_cross =     array(2)       { [0]=> array(3)           { ["cat_cross_id"]=> string(2) "24"              ["cat_cross_items_id"]=> string(1) "4"              ["cat_cross_user_id"]=> string(2) "58"            }          [1]=> array(3)           { ["cat_cross_id"]=> string(2) "25"              ["cat_cross_items_id"]=> string(1) "6"              ["cat_cross_user_id"]=> string(2) "58"            }       } 

now want query values of "cat_cross_items_id" because need later compare in if-clause other var.

i tried one:

$allowed = array("cat_cross_items_id"); var_dump(array_intersect_key($cat_cross, array_flip($allowed))); 

i think works on first level of array, how can filter second on?

desire result:

$new_arr = array(4,6) 

thank much!

php >= 5.5.0:

$new_arr = array_column($cat_cross, "cat_cross_items_id"); 

php >= 5.3.0:

$new_arr = array_map(function($v) { return $v["cat_cross_items_id"]; }, $cat_cross); 

earlier version need loop or call outside function in array_map().


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -