Advertisement
Guest User

Untitled

a guest
May 30th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <?php
  2. function compareArray($parameter){
  3. $products = array(
  4. 'paper' => array(
  5. 'copier' => "B",
  6. 'inkjet' => "Inkjet Printer",
  7. 'laser' => "Laser Printer",
  8. 'photo' => "Photographic Paper"),
  9. 'pens' => array(
  10. 'copier' => "A",
  11. 'inkjet' => "Highlighters",
  12. 'marker' => "Markers"),
  13. 'misc' => array(
  14. 'copier' => "C",
  15. 'inkjet' => "Adhesives",
  16. 'clips' => "Paperclips")
  17. );
  18.  
  19. $a = array();
  20. echo "<pre>";
  21. foreach($products as $section => $items)
  22. foreach($items as $key => $value)
  23. if ($key == $parameter){
  24. // echo "$key => $value";
  25. // echo "<br>";
  26. array_push($a,$value);
  27. }
  28. // echo "$section:\t$key\t($value)<br>";
  29. print_r($a);
  30. $b = $a;
  31. sort($b);
  32. print_r($b);
  33. if ($a == $b){
  34. print_r("Arrays are the same");
  35. return true;}
  36. else{
  37. print_r("Arrays are different");
  38. return false;
  39. }
  40. echo "</pre>";
  41. }
  42. compareArray(copier);
  43. compareArray(inkjet);
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement