php - Compare multiple arrays for all keys -
i have little problem php arrays , comparing i'd do. sorry bad english language :(
i'm building image management system. user can select multiple pictures @ time, , edit info selected pictures. fields filled in - , i'd show user '*' char if specific field filled different info multiple pictures.
my problem next : - have two-dimension array containing mysql query results pictures selected (this number of course of study indefinite). here's illustration of resulting array :
array ( [0] => array ( [folder_id] => 40 [title_fr] => test [title_en] => [desc_fr] => [desc_en] => [place_fr] => koksijde, belgique [place_en] => koksijde, kingdom of belgium [place_icao] => ebbe [place_city] => [place_country] => ) [1] => array ( [folder_id] => 40 [title_fr] => test [title_en] => [desc_fr] => [desc_en] => [place_fr] => koksijde, belgique [place_en] => koksijde, kingdom of belgium [place_icao] => ebbe [place_city] => [place_country] => ) [2] => array ( [folder_id] => 40 [title_fr] => test [title_en] => [desc_fr] => [desc_en] => [place_fr] => koksijde, belgique [place_en] => koksijde, kingdom of belgium [place_icao] => ebbe [place_city] => [place_country] => ) [3] => array ( [folder_id] => 51 [title_fr] => test [title_en] => [desc_fr] => [desc_en] => [place_fr] => franc [place_en] => angle [place_icao] => engl [place_city] => münich2 [place_country] => de )
as can see, fields may mutual records, may different. instance, [place_fr] not same records, [desc_fr] is.
i'd code function returns array fields key, , '*' value if field contains different values between records, , value if mutual records.
for instance, result here :
array ( [folder_id] => * [title_fr] => test [title_en] => [desc_fr] => [desc_en] => [place_fr] => * [place_en] => * [place_icao] => * [place_city] => * [place_country] => * )
i know done using array_diff_assoc(). it's quite easy done 2 arrays. problem have pass undefinite number of arguments function , don't know how solved.
sorry noob question - i'm beginer when comes arrays.
thanks help !
this should it:
// mutual keys => values $common = call_user_func_array('array_intersect_assoc', $arr); // , append missing keys them, "*" values $common += array_fill_keys(array_keys($arr[0]), '*');
(assuming $arr
array above)
php arrays multidimensional-array comparison
No comments:
Post a Comment