PHP - If / Else ... statement - Syntax Differences

Php noob here. The company I really work for has an if / else statement created as follows:

{if product_type != ""} {product_type} {if:else}No Product Type{/if} 

Other studies that I do provide a format such as:

 <?php if ($bodyID==='home') { ?> <h1>I am home!</h1> <?php } else { ?> <p>I'm not home!</p> <?php } ?> 

Is there a specific reason for the differences in syntax or is this how the previous developer wrote?

+5
source share
2 answers

The first one is not php, it is a template engine, possibly https://ellislab.com/expressionengine/user-guide/templates/conditionals.html . The second is valid php code.

+2
source

If-Else syntax allows you to bind a score to the first if statement. This is pseudo code, not PHP:

 If (Johnny > 18){ Johnny is a minor} else if (Johnny < 65) { Johnny is an adult} else {Johnny is eligible for Social Security} 

From the question you asked, it is possible that the second if condition is nested in the if-else statement of the first.

 If (x > 0){ do Y} Else{ If(x < 100){do Z} Else {do A} } 
0
source

Source: https://habr.com/ru/post/1214194/


All Articles