You were close to the solution but your main error was here:
if(in_array($i, $arr[$i]){
Here you try to access the index $i in your original array $arr. That array only has two of them - 0 and 1. On the other hand, your loop will run from 1 to 7, causing "Undefined index" notices for anything greater than 1.
You seem to be familiar with the array_column function since you use it to determine how far your loop should go:
max(array_column($arr, 'index'))
And this is exactly what you should compare against. This returns a simple array [5, 7] which can then be used as a haystack value for in_array:
$arr = array(
array("index"=>"5"),
array("index"=>"7"),
);
$indices = array_column($arr, 'index'); // store it as you have to use it multiple times
for ($i = 1; $i <= max($indices); $i++) {
if (in_array($i, $indices)) {
var_dump('true '.$i);
} else {
var_dump('false '.$i);
}
}
This will output:
'false 1'
'false 2'
'false 3'
'false 4'
'true 5'
'false 6'
'true 7'
if(in_array($i, $arr[$i]){and$i == maxshould be$i = max. You were close with the general idea, though. You just need to usearray_column($arr, 'index')instead of$arr[$i].$i <= maxbut output is still false if index 5 and index 7