Honesty Rocks! truth rules.

Endif function?

HOME      >>       Programming

alex1985

As you get noticed before, I am studying PHP in examples like using the tutorials as well as books itself. Through my readings, I get this function

<?php endif; ?>
a lot of times. So, what do you mean by this function, and what does it do exactly?

sonesay

Google = http://www.phpbuilder.com/

It looks like it just closes the if statement blocks you make. I never use it so I don't think you should worry about closing it either. I doubt many people use it as its more unnecessary typing.


darran

More often than not I would use the {} instead of the endif statement. It is just redundant in my opinion. So it would look something like this:

<?php if ($number == 1) { ----some code here----}<?php>


truefusion

Looks like something you'd see in Python. But i've been spoiled by the curly brackets. <_< It's so much quicker to type curly brackets, which is why i haven't taken the time to learn Python.


alex1985

It's still complicated for me?!


rvalkass

There are three ways to write an if statement depending on what you want to do and what your coding style is like. I shall give examples below:

 

"Standard" If Statement

This is your bog standard if statement, used millions of times by pretty much everyone:

 

if ( condition ) { code to execute if condition === TRUE}

If the condition is true then the code between the curly braces - { } - gets run. If the condition is false then the code between the curly braces is ignored.

 

"Verbose" If Statement

This is the slightly longer/older style if statement. It is more similar to if statements in older programming languages.

 

if ( condition ) : Code here is executed if condition === TRUEendif;

Here the code that gets run if the condition is true starts with a colon : and ends with endif;

This is sometimes useful to use if there are lots of curly braces dotted around your script, as it makes clear exactly what you are closing (if, while, else, foreach, etc.).

 

"Short" If Statement

This is used to execute one command, and only one command, when the condition is true. It has no real start or end, and is simply made up with the if statement. Whatever the next line is is only executed when the condition is true.

 

if ( condition ) This line gets executed if condition === TRUE;This line is always run;So is this one;

The line that is part of the if statement usually gets indented to make it clearer that it is only run when the if statement is true.

 

You might want to take a look at the following two manual pages for more information about exactly how they work if it still isn't totally clear:

http://forums.xisto.com/no_longer_exists/

http://forums.xisto.com/no_longer_exists/


alex1985

There are three ways to write an if statement depending on what you want to do and what your coding style is like. I shall give examples below:

 

"Standard" If Statement

This is your bog standard if statement, used millions of times by pretty much everyone:

 

if ( condition ) { code to execute if condition === TRUE}

If the condition is true then the code between the curly braces - { } - gets run. If the condition is false then the code between the curly braces is ignored.

 

"Verbose" If Statement

This is the slightly longer/older style if statement. It is more similar to if statements in older programming languages.

 

if ( condition ) : Code here is executed if condition === TRUEendif;

Here the code that gets run if the condition is true starts with a colon : and ends with endif;

This is sometimes useful to use if there are lots of curly braces dotted around your script, as it makes clear exactly what you are closing (if, while, else, foreach, etc.).

 

"Short" If Statement

This is used to execute one command, and only one command, when the condition is true. It has no real start or end, and is simply made up with the if statement. Whatever the next line is is only executed when the condition is true.

 

if ( condition ) This line gets executed if condition === TRUE;This line is always run;So is this one;

The line that is part of the if statement usually gets indented to make it clearer that it is only run when the if statement is true.

 

You might want to take a look at the following two manual pages for more information about exactly how they work if it still isn't totally clear:

http://forums.xisto.com/no_longer_exists/

http://forums.xisto.com/no_longer_exists/


Oh, thanks. It's clear now!!!