elseif Statement - PHP - P26
When you have more than 2 outcomes in your decision making, you're going to need to use the elseif statement. The elseif keyword goes in between the if and the else keywords. Your primary condition is handled by the if statement. If the condition is met inside of the if statement, there's no point in testing any other conditions. The code that's inside of the if statement body is executed and the remainder of the elseif/else statements are skipped.
When the condition is not met, PHP will check the elseif statements next. If a condition matches, the code inside of that particular elseif statement body will execute and PHP will skip the remainder of the elseif/else testing.
If no conditions are met, the PHP will execute the code inside of the else statement body.
The anatomy of the if/elseif/else statement looks like this:
if ( conditional expression ) {
expression
} elseif ( conditional expression ) {
expression
} else {
expression
}
Time for a quick example. If we did everything correctly, only one expression will execute inside of the if/elseif/else structure.
$car = "Corvette";
if ( $car == "Subaru" ) {
echo "Subie Wave";
} elseif ( $car == "Jeep" ) {
echo "Jeep Wave";
} elseif ( $car == "Corvette" ) {
echo "Corvette Wave";
} else {
echo "No Wave";
}
Let's see what PHP does when evaluating the code above.
1. PHP assigns the value Corvette to the $car variable.
2. PHP encounters the if statement. It tests to see if the value that's stored inside of the $car variable is equal to Subaru. Since it's not, it moves on to the elseif statement.
3. It tests to see whether the value that's stored inside of the $car variable is equal to Jeep. Since it's not, it moves on to the next statement.
4. PHP tests to see whether the value that's stored inside of the $car variable is equal to Corvette. It is.
5. PHP executes the code inside of that elseif statement. PHP outputs Corvette Wave.
6. It skips over the else statement since it already found a match.
Read the full article on my website
https://www.dinocajic.com/php-elseif-statement/
Code for this tutorial
https://github.com/dinocajic/php-7-youtube-tutorials/blob/master/26%20Else%20If%20Statements.php
Full Code
https://github.com/dinocajic/php-7-youtube-tutorials
PHP Playlist
https://www.youtube.com/playlist?list=PLbhJy0VhR6SAmoneYvF6Y_axQJKg7i50M
--
Dino Cajic
Author and Head of IT
Homepage: https://www.dinocajic.com
GitHub: https://github.com/dinocajic
Medium: https://medium.com/@dinocajic
Instagram: https://www.instagram.com/think.dino
LinkedIn: https://www.linkedin.com/in/dinocajic/
Twitter: https://twitter.com/dino_cajic
My Books
An Illustrative Introduction to Algorithms
https://www.amazon.com/dp/1686863268
Laravel Excel: Using Laravel to Import Data
https://amzn.to/4925ylw
Code Along With Me - PHP: From Basic to Advanced PHP Techniques
https://amzn.to/3M6tlGN
8-Bit March by Twin Musicom is licensed under a Creative Commons Attribution license (https://creativecommons.org/licenses/by/4.0/)
Artist: http://www.twinmusicom.org/
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «elseif Statement - PHP - P26», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.