Lodius2000 Posted October 17, 2008 Share Posted October 17, 2008 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 Link to comment https://forums.phpfreaks.com/topic/128798-solved-quickie-regarding-arrays-and-numbers/ Share on other sites More sharing options...
Lodius2000 Posted October 17, 2008 Author Share Posted October 17, 2008 figured it out foreach ($order_ids as $i){ if ($i > $id2){ $errors[] = 'The number '.$i.' in the Order field is invalid, please replace it with another number'; } } Link to comment https://forums.phpfreaks.com/topic/128798-solved-quickie-regarding-arrays-and-numbers/#findComment-667745 Share on other sites More sharing options...
kenrbnsn Posted October 17, 2008 Share Posted October 17, 2008 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 Link to comment https://forums.phpfreaks.com/topic/128798-solved-quickie-regarding-arrays-and-numbers/#findComment-667755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.