Home > Backend Development > PHP Tutorial > Why do some PHP frameworks choose if ():else: endif to limit the range instead of {}

Why do some PHP frameworks choose if ():else: endif to limit the range instead of {}

WBOY
Release: 2016-08-04 09:20:59
Original
1249 people have browsed it

Why some php frameworks choose

<code><?php 
    if():
    // some code
    endif;
?></code>
Copy after login
Copy after login

to limit the range instead of using

<code><?php
    if(){
    //some code
    }
?></code>
Copy after login
Copy after login

//---- Additional question ----
Is there any performance difference between the two?

After reading the answers of several students, whether they are clear or not, I feel that both are quite clear ^_^

Reply content:

Why some php frameworks choose

<code><?php 
    if():
    // some code
    endif;
?></code>
Copy after login
Copy after login

to limit the range instead of using

<code><?php
    if(){
    //some code
    }
?></code>
Copy after login
Copy after login

//---- Additional question ----
Is there any performance difference between the two?

After reading the answers of several students, whether they are clear or not, I feel that both are quite clear ^_^

Generally, the first syntax is more suitable for nesting in HTML.
For example

<code class="php"><?php if($value): ?>
<div>aaaaa</div>
<?php else: ?>
<div>bbbbb</div>
<?php endif; ?></code>
Copy after login

Isn’t it better than

<code class="php"><?php if($value){ ?>
<div>aaaaa</div>
<?php }else{ ?>
<div>bbbbb</div>
<?php } ?></code>
Copy after login

More clear!

The meaning expressed by the two ways of writing is exactly the same, but they look different. The first one is the same as mentioned above. When there is html code, the statement will appear particularly clear. The second one is usually written in a pure php file. , I think I have a strong sense of logic.

<code>    }
}</code>
Copy after login
<code>    endforeach;
endif;</code>
Copy after login

When the code is relatively long, it will be clearer when you look at the tail
But as other answers said, it is more readable when nested in html

Personally I hate this way of writing:

<code>if():
// some code
endif;</code>
Copy after login

?>

You use

<code><?php
if ()
{
}
else
{
}
?></code>
Copy after login

It’s the same, the effect is the same.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template