<?php
$id=5;
$allProducts[] = array('itemid'=>$id,'qty' => 1);
$allProducts[] = array('itemid'=>6,'qty' => 1);
// old version
if(array_search($id,array_column($allProducts, 'itemid'))) {
echo "an item was found\n"; // will not work
} else {
echo "NO Item was found, though it should be there\n";
}
// corrected version
if(array_search($id,array_column($allProducts, 'itemid')) !== false) {
echo "an item was found and has the key " .array_search($id,array_column($allProducts, 'itemid'));
}
NO Item was found, though it should be there
an item was found and has the key 0
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
NO Item was found, though it should be there
an item was found and has the key 0