Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Endif function?
alex1985
post Mar 19 2008, 08:14 AM
Post #1


Super Member
*********

Group: [HOSTED]
Posts: 411
Joined: 9-February 08
Member No.: 57,615



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
CODE
<?php endif; ?>
a lot of times. So, what do you mean by this function, and what does it do exactly?
Go to the top of the page
 
+Quote Post
sonesay
post Mar 19 2008, 08:33 AM
Post #2


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 681
Joined: 20-June 07
From: Auckland
Member No.: 45,102



Google = http://www.phpbuilder.com/manual/en/migration.if-endif.php

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.
Go to the top of the page
 
+Quote Post
darran
post Mar 19 2008, 09:58 AM
Post #3


Privileged Member
*********

Group: Members
Posts: 661
Joined: 31-August 06
From: Singapore
Member No.: 29,189



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:

CODE
<?php if ($number == 1) {
        ----some code here----
}<?php>
Go to the top of the page
 
+Quote Post
truefusion
post Mar 19 2008, 01:10 PM
Post #4


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,896
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528
T17 GFX Crew



Looks like something you'd see in Python. But i've been spoiled by the curly brackets. biggrin.gif It's so much quicker to type curly brackets, which is why i haven't taken the time to learn Python.
Go to the top of the page
 
+Quote Post
alex1985
post Mar 19 2008, 05:17 PM
Post #5


Super Member
*********

Group: [HOSTED]
Posts: 411
Joined: 9-February 08
Member No.: 57,615



It's still complicated for me?!
Go to the top of the page
 
+Quote Post
rvalkass
post Mar 19 2008, 05:37 PM
Post #6


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,119
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



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:

CODE
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.

CODE
if ( condition ) :
    Code here is executed if condition === TRUE
endif;


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.

CODE
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://uk2.php.net/manual/en/control-structures.if.php
http://uk2.php.net/manual/en/control-struc...tive-syntax.php
Go to the top of the page
 
+Quote Post
alex1985
post Mar 19 2008, 05:40 PM
Post #7


Super Member
*********

Group: [HOSTED]
Posts: 411
Joined: 9-February 08
Member No.: 57,615



QUOTE(rvalkass @ Mar 19 2008, 09:37 PM) *
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:

CODE
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.

CODE
if ( condition ) :
    Code here is executed if condition === TRUE
endif;


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.

CODE
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://uk2.php.net/manual/en/control-structures.if.php
http://uk2.php.net/manual/en/control-struc...tive-syntax.php



Oh, thanks. It's clear now!!!
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Delphi(1)
  2. Getting List Of Directories And Files Using Php(6)
  3. How To Use A Link To Call Function In Php?(8)
  4. Include File.php?id=something(13)
  5. Regexp Function Preg_match_all()(0)
  6. Did This Hosting Service Support This Function ?(1)
  7. Explode Function Help(1)
  8. Genuine Help With Smtp And Php Mail() Function(3)
  9. Errors With Php Setcookie() And Headers! Please Help!(2)
  10. How Good Is This Data Cleaning Function?(2)
  11. The Extract() Function(6)
  12. Using The / As A Delimiter In The Split Function(2)
  13. Error With Joomla Template(1)
  14. Php - Randomize Web Title(5)
  15. [php] Header Function(2)
  1. [php](simple) Using Functions To Combine Values In A Form(2)
  2. Mail() Clone(5)
  3. The Best Zip Function(1)
  4. Php Explode Function Help(4)
  5. How To Check If Fsockopen Function Is Enabled?(2)
  6. Problem With Where Clause And Max Function(2)
  7. Arrays Outside A Function(3)
  8. Inkscape, A Open Source Vector App That Support Lot Function.(0)
  9. Help: Disable All Buttons Inside A Div Element(8)
  10. User Permission Function [php](3)
  11. Php - Forms, Date And Include(0)
  12. Question Regarding Php Function(12)
  13. PHP Function To Add Previous and Next Page Feature(2)