fork download
  1. <?php
  2.  
  3. $tiger = array ("orange", "white");
  4. $cat = array ("black", "white", "brown");
  5. $fruit = array ("purple", "red", "green", "brown");
  6.  
  7. $arrays = compact('tiger', 'cat', 'fruit');
  8. $values = array_unique(call_user_func_array('array_merge_recursive', $arrays));
  9.  
  10. foreach ($values as $value) {
  11. $found = array();
  12. foreach ($arrays as $name => $bag) {
  13. if (in_array($value, $bag)) {
  14. $found[] = $name;
  15. }
  16. }
  17. echo "$value: ".implode(", ", $found)."\n";
  18. }
  19.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
orange: tiger
white: tiger, cat
black: cat
brown: cat, fruit
purple: fruit
red: fruit
green: fruit