Search multidimensional array in PHP and return keys -


i'm facing following issue: i've set website representing "icon library". shows contents of csv file containing additional attributes icon, e.g.

  • file name
  • tooltip
  • tags
  • state (done, in progress)
  • file types
    • png
      • file name found in directory
    • eps
      • file name found in directory
    • ico
      • file name found in directory
    • ...

in end put big array:

[390] => array     (         [0] => hammer         [1] => properties         [2] => tools, hammer, properties         [3] =>          [4] => done         [png] => array             (                 [0] => hammer_16x.png                 [1] => hammer_32x.png             )          [eps] => array             (                 [0] => hammer_16x.eps                 [1] => hammer_32x.eps             )          [ico] => array             (                 [0] => hammer.ico             )      ) 

now provide possibility search in array , filter contents displayed on website based on search result. therefore search @ least following strings:

 [0] => hammer  [1] => properties  [2] => tools, hammer, properties  [3] =>   [4] => done 

any hints how that? lot!

you may use array_filter in conjunction array_diff_assoc. somehow this:

function filter($array, $filter_elem) {     return array_filter($array, function ($v) use($filter_elem) {         return count(array_diff_assoc($filter_elem, $v)) == 0;     }); }  $array = array(     '390' => array(         '0' => 'hammer',         '1' => 'properties',         '2' => 'tools, hammer, properties',         '3' => false,         '4' => 'done',         'png' => array(             '0' => 'hammer_16x.png',             '1' => 'hammer_32x.png',         ),         'eps' => array(             '0' => 'hammer_16x.eps',             '1' => 'hammer_32x.eps',         ),         'ico' => array(             '0' => 'hammer.ico',         ),     ),     ... );  $filter_elem = array(     '1' => 'properties',     '2' => 'tools, hammer, properties',     '3' => false,     '4' => 'done', );  print_r(filter($array, $filter_elem)); 

demo


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -