global $arr; $check_numbers = array(146, 284, 871); foreach ($check_numbers as $elem) { if (!in_array($elem, $arr)) { echo "The number {$elem} [does not] exist in the array <br />"; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <style type="text/css"> span { color:red; } </style> </head> <body> <?php print_r(find_3_prime()); echo "<br />"; print_r($arr); echo "<br />"; print_r(check_exists()); ?> </body> </html>
if (is_prime($value)) { $i++; } if ($i == 3) { return $value; break; } } if ($i < 3) { return "not found"; } } function check_exists($ar) { $s = "The number %d %s exist in the array.<br>"; $array = array(146, 284, 871); foreach ($array as $value) { if (in_array($value, $ar)) { printf($s, $value, ""); } else { printf($s, $value, "does not"); } } } printf("Third prime number: %s <br>", find_3_prime($arr)); check_exists($arr); ?> </body> </html>
<?php error_reporting(E_ALL); require_once 'functions.php'; $numbers = range(20, 1000, 37); find_3_prime($numbers); check_exists($numbers); function find_3_prime($numbers) { $primesCount = 0; foreach ($numbers as $number) { if (is_prime($number)) { $primesCount++; } if ($primesCount == 3) { echo "{$number}<br />"; break; } } } function check_exists($numbers) { $toCeck = array(146, 284, 871); foreach ($toCeck as $number) { $not = in_array($number, $numbers) ? '' : ' does not'; echo "The number {$number}{$not} exists in the array.<br />"; } }