0

I am currently struggling to compare two arrays.

The first array ($allRoepnummerArray) contains all the callnumbers available.

The second array ($occupiedRoepnummers) contains the call numbers that are occupied.

At the moment I am unable to compare them.

I would like to have the available call numbers in a table.

$allRoepnummerArray = array(
                                '22-101',
                                '22-102',
                                '22-103',
                                '22-104',
                                '22-105',
                                '22-106',
                                '22-107',
                                '22-108',
                                '22-109',
                                '22-110',
                                '22-111',
                                '22-112',
                                '22-113',
                                '22-114',
                                '22-115',
                                '22-116',
                                '22-117',
                                '22-118',
                                '22-119',
                                '22-120',
                                '22-121',
                                '22-122',
                                '22-123',
                                '22-124',
                                '22-125',
                                '22-126',
                                '22-127',
                                '22-128',
                                '22-129',
                                '22-130',
                            );

                            $occupiedRoepnummers = array();

                            foreach ($roepnummerResults as $roepnummerKey => $roepnummerValue) {
                                array_push($occupiedRoepnummers, $roepnummerValue['roepnummer']);
                            }

                            foreach($allRoepnummerArray as $allRoepnummer) {
                                foreach($occupiedRoepnummers as $occupiedRoepnummer) {

                                    if ($allRoepnummer != $occupiedRoepnummer) {
                                        echo '<th>'.$allRoepnummer.'</th>';
                                    }

                                }
                            }
                            ?>
1
  • What's the desired output? Commented Sep 25, 2020 at 12:36

3 Answers 3

2

You can subtract arrays with array_diff(). In your case you could do:

$availableRoepnummers = array_diff($allRoepnummerArray, $occupiedRoepnummers);

You can then make a HTML table of the $availableRoepnummers.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I tried that before but it didn't worked out. But thanks!
2

try this:

foreach($allRoepnummerArray as $allRoepnummer) {
if (!in_array($allRoepnummer,$occupiedRoepnummers)) {
                                    echo '<th>'.$allRoepnummer.'</th>';
                                }}

1 Comment

@max check my answer now just copy it and it will work
0

use array_intersect() function like below it will retrun only matched values

$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"black","g"=>"purple");
$a3=array("a"=>"red","b"=>"black","h"=>"yellow");

$result= array_intersect($a1,$a2);
print_r(array_diff($a1,$result));

result : Array ( [b] => green [c] => blue [d] => yellow )

1 Comment

I need tot non matched values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.