2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Conditionals
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Conditionals
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Conditionals in PHP are written using the `if` , `elseif` , `else`  syntax. Using conditionals allows you to perform different actions depending on different inputs and values provided to a page at run time. In PHP conditionals are often referred to as control structures.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### If
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```PHP
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< ?php 
						 
					
						
							
								
									
										
										
										
											2018-12-12 21:37:07 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if ($_GET['name'] == "freecodecamp"){
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  echo "You viewed the freeCodeCamp Page!";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Elseif
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```PHP
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< ?php 
						 
					
						
							
								
									
										
										
										
											2018-12-12 21:37:07 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if ($_GET['name'] == "freecodecamp"){
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  echo "You viewed the freeCodeCamp Page!";
							 
						 
					
						
							
								
									
										
										
										
											2018-12-12 21:37:07 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} elseif ($_GET['name'] == "freecodecampguide"){
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  echo "You viewed the freeCodeCamp Guide Page!";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Else
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```PHP
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< ?php 
						 
					
						
							
								
									
										
										
										
											2018-12-12 21:37:07 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if ($_GET['name'] == "freecodecamp"){
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  echo "You viewed the freeCodeCamp Page!";
							 
						 
					
						
							
								
									
										
										
										
											2018-12-12 21:37:07 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} elseif ($_GET['name'] == "freecodecampguide"){
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  echo "You viewed the freeCodeCamp Guide Page!";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} else {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  echo "You viewed a page that does not exist yet!";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Note
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								In cases where you have a lot of possible conditions you may want to use a < a  href = "/php/switch" > Switch Statement< / a > .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#### More Information:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  < a  href = "https://secure.php.net/manual/en/control-structures.elseif.php"  rel = "nofollow" > php.net control structures manual</ a >