<?php
//Sample application to find available values in a merged collection:
function checkVacancies
(array $positions) {
$available = [];
foreach ($positions as $position => $optionAvailable) {
$nextBox = false;
$prevBox = false;
if (isset($positions[$position+1])) { $nextBox = $positions[$position+1];
}
if (isset($positions[$position-1])) { $prevBox = $positions[$position-1];
}
if ($nextBox == false && $prevBox == false && $optionAvailable == false) {
$available[] = $position;
}
}
return $available;
}
//false is returned position only if there is a real approximate value
$positions = [
true, //0
false,
false, //2
false,
true,
false,
false, //8
false, //
false
];
print_r(checkVacancies
($positions));
PD9waHAKCi8vU2FtcGxlIGFwcGxpY2F0aW9uIHRvIGZpbmQgYXZhaWxhYmxlIHZhbHVlcyDigIvigItpbiBhIG1lcmdlZCBjb2xsZWN0aW9uOgoKZnVuY3Rpb24gY2hlY2tWYWNhbmNpZXMoYXJyYXkgJHBvc2l0aW9ucykgewoKICAgICRhdmFpbGFibGUgPSBbXTsKCmZvcmVhY2ggKCRwb3NpdGlvbnMgYXMgJHBvc2l0aW9uID0+ICRvcHRpb25BdmFpbGFibGUpIHsKIAogICAgICAgJG5leHRCb3ggPSBmYWxzZTsKICAgICAgICAkcHJldkJveCA9IGZhbHNlOwoKICAgICAgICBpZiAoaXNzZXQoJHBvc2l0aW9uc1skcG9zaXRpb24rMV0pKSB7CiAgICAgICAgICAgJG5leHRCb3ggPSAkcG9zaXRpb25zWyRwb3NpdGlvbisxXTsKICAgICAgICB9CiAgICAgICAgaWYgKGlzc2V0KCRwb3NpdGlvbnNbJHBvc2l0aW9uLTFdKSkgewogICAgICAgICAgICRwcmV2Qm94ID0gJHBvc2l0aW9uc1skcG9zaXRpb24tMV07CiAgICAgICAgfQoKICAgICAgICBpZiAoJG5leHRCb3ggPT0gZmFsc2UgJiYgJHByZXZCb3ggPT0gZmFsc2UgJiYgJG9wdGlvbkF2YWlsYWJsZSA9PSBmYWxzZSkgIHsKICAgICAgICAgICAgICRhdmFpbGFibGVbXSA9ICRwb3NpdGlvbjsKICAgICAgICAgfQoKICB9CiAgICAg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