The goal is to compare the current array element qty with the previous and if the condition is met return success, i.e: if current element qty is 0 and the previous element qty is greater than 5 return.
Research keeps popping up PHP's current(), next(), and prev() tools however I'm not getting the return I hope for with these attempts:
1.
for($i = 0; $i < $length -1; ++$i){
if(current($myArray[0]['qty']) == 0 && prev($myArray[0]['qty']) > 5){
echo 'success!';
}
}
2.
foreach($myArray as $item){
if(current($item['qty']) == 0 && prev($item['qty'] > 5)){
echo 'success!';
} else {
continue;
}
}
Admittedly I'm not familiar with all of PHP's available tools and options so if there's something else I should be learning about and using I'd be grateful for suggestions.
Here's my sample array:
$myArray = Array
(
[0] => Array
(
[0] => foo
[name] => foo
[1] => 15
[qty] => 15
)
[1] => Array
(
[0] => bar
[name] => bar
[1] => 0
[qty] => 0
)
[2] => Array
(
[0] => baz
[name] => baz
[1] => 47
[qty] => 47
)
)
My desired result would be the following for an automatic email: **bar** is empty, check **foo** for replenishment!
$ifrom yourforloop to address the array ?