PHP function that finds all prime numbers within a given range | Nested for loop
In this video, we are going to learn how to find all prime numbers within a given range. For those who don’t know, a prime number is an integer that only has two divisors, namely 1 and the integer itself, e.g.
1 x 7 = 7
1 x 11 = 11
1 x 23 = 23
1 x 37 = 37
1 x 41 = 41
1 x 53 = 53
In order to find all prime numbers within a given range, we need a PHP function. We will call this function find_prime_numbers(). Because there are infinitely many prime numbers, the function must be given a specific range within which to search for prime numbers. Thus, the first argument of the function is the lower limit of the range. Its default value is 1. The second argument of the function is the upper limit of the range. Its default value is 1000. And the output of the function is an array that contains all prime numbers from within the given range.
First, we declare the array that is going to store all prime numbers. Then, we use a nested for loop, i.e. a for loop inside another for loop. We use the outer for loop to loop through the range of numbers, and the inner for loop to find the divisors of each number within the range. If a number only has two divisors, namely 1 and itself, then that number is a prime number. Finally, we build up the array that is going to store all prime numbers within the range, and return it.
Further links
PHP function that finds all divisors of a number: https://youtu.be/g0x2OTujpZo
/* *** *** *** *** *** *** *** */
If you want to watch videos about mathematics and physics, you can subscribe to my second YouTube channel: https://www.youtube.com/@Sohcahtoa1609?sub_confirmation=1.
You can support my work by becoming a patron: https://patreon.com/Sohcahtoa1609
Follow Sohcahtoa1609 on Twitter: https://twitter.com/Sohcahtoa1609
Like Sohcahtoa1609 on Facebook: https://facebook.com/Sohcahtoa1609
Follow Sohcahtoa1609 on Instagram: https://instagram.com/Sohcahtoa1609
Disclaimer: this video is meant to be a proof of concept.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «PHP function that finds all prime numbers within a given range | Nested for loop», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.