Jump to content

[SOLVED] quickie regarding arrays and numbers


Lodius2000

Recommended Posts

I want to check that an the contents of an array are less that a specific number and i need to work it into an if clause that returns negative, if the array contains 1 value that is higher than the number

 

would

if( $array[] >= $number){

throw an error here

}

do it 

if not what would

thanks

Try something like this:

<?php
$nums = range(1,999);
shuffle($nums);
$rand_nums = array_slice($nums,0,rand(10,50));

function check_array($ary, $max) {
   foreach ($ary as $num)
       if ($num > $max) return false;
   return true;
}

$max = rand(100,1800);
$does = (check_array($rand_nums,$max))?' all less than ':' not all less than ';
echo 'The array (' . implode(', ',$rand_nums) . ') is' . $does . $max;
?>

 

Ken

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.