fork download
  1. <?php
  2.  
  3. $all = array( 0=>array(
  4. //index 0 has value 'Luxury Room' (room title)
  5. 0=>'Luxury Room',
  6. //index 1 is an array
  7. 1=>array(
  8. //where index 0 has value 'xx1' (bed code)
  9. 0=>'xx1',
  10. //where index 1 has value 'xx2' (bed code)
  11. 1=>'xx2')),
  12. //again index 1 is an array etc. just as above...
  13. 1=>array(
  14. 0=>'Cheap Room',
  15. 1=>array(
  16. 0=>'zz1',
  17. 1=>'zz2',
  18. 2=>'zz3',
  19. 3=>'zz4')));
  20.  
  21. $reserved = array( 0=>array(
  22. 0=>'Luxury Room',
  23. 1=>array(0=>'xx2')));
  24.  
  25. foreach ($all as &$room) {
  26. foreach ($reserved as $r) {
  27. if ($room[0] == $r[0]) { // same types of room
  28. foreach ($room[1] as $i => $code) {
  29. if (in_array($code, $r[1])) {
  30. unset($room[1][$i]);
  31. }
  32. }
  33. }
  34. }
  35. $room[1] = array_values($room[1]); // Reset array indexes
  36. }
  37.  
  38. print_r($all);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => Luxury Room
            [1] => Array
                (
                    [0] => xx1
                )

        )

    [1] => Array
        (
            [0] => Cheap Room
            [1] => Array
                (
                    [0] => zz1
                    [1] => zz2
                    [2] => zz3
                    [3] => zz4
                )

        )

)