Thank you
Shears
Moderator: General Moderators
Code: Select all
function checkValue (&$val, $key)
{
if ($val < 0) {
trigger_error('Value must be positive for ' . $key, E_USER_WARNING);
}
}
array_walk($array, 'checkValue');While array_filter() might work too, it's not logical to use it here - it's not array_filter()'s purpose.scottayy wrote:array_filter() could also be used, with a simple callback function like jenk provided.
Code: Select all
function checkValue (&$val)
{
if ($val >= 0) {Echo 'Update ';
} elseif ($val < 0) {Echo 'Not enough weapons in armoury for sale to take place.</p>';
}
}
array_walk($numitems, 'checkValue');Code: Select all
foreach ($array as $val) {
if ($val < 0) {
echo 'Not enough weapons in armory for sale';
$var = null;
break;
} else {
$var = 'update';
}
}
//do something with $varCode: Select all
$hasNegatives = min($array) < 0;