|
| |||||||||
| Tags: control structures, html code, php, programming language, syntax |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| How to use an Alternative Syntax for Control Structures in PHP?
Hi everyone, I have recently started with the PHP programming language. I have just finished with some simple loops that are used in PHP coding. I came to know that there is an alternate way for the syntax of the control structures. But I don't know anything more than this.!! So thought that you guys are better for explaining the topics. Please explain me how to use an Alternative Syntax for Control Structures in PHP? Thanks for Sparing the Time (Advance).
__________________ As you simplify your life, the laws of the universe will be simpler; solitude will not be solitude, poverty will not be poverty, nor weakness.Henry David Thoreau |
|
#2
| ||||
| ||||
| Re: How to use an Alternative Syntax for Control Structures in PHP?
You should know that PHP offers another way to gather statements inside a block for control functions if, while, for, foreach, and switch. In each case, the principle is to replace the opening brace by two colon ( : ) and the closing brace to endif;, endwhile;, endfor;, endforeach; or endcase. All PHP scripts are a sequence of instructions. A statement can be an assignment, a function call, a conditional statement or a statement that does nothing (an empty statement). A statement usually ends with a semicolon ( ";"). In addition, statements can be grouped into block delimited by curly braces ( "()"). A block is considered as an instruction. |
|
#3
| ||||
| ||||
| Re: How to use an Alternative Syntax for Control Structures in PHP?
PHP offers an alternative syntax for some of its control structures. In the below example, the HTML block "A is equal to 4" is nested within an if using this new syntax. This HTML code will be displayed if the variable $ a is equal to 4. PHP Code:
__________________ Signatures reduce available bandwidth |
|
#4
| ||||
| ||||
| Re: How to use an Alternative Syntax for Control Structures in PHP?
I am giving you an alternate syntax for the example provided by the 'Viensterrr' which applies to else and elseif as well. The following is an if structure with elseif and else in the alternative format : PHP Code:
__________________ I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame. |
|
#5
| ||||
| ||||
| Re: How to use an Alternative Syntax for Control Structures in PHP?
You can not use different syntax in the same control block. When you going to make a script , you must try easiest way to do and fastest way to parse. Using alternative-syntax is very useful to shorten your code. The end_; structure sometimes makes it easier to tell which block statement end you are looking at. It's much harder to tell which nested block a } belongs to than an end_;. Hope that you got the point I was trying to explain.!! ![]() |
|
#6
| |||
| |||
| Re: How to use an Alternative Syntax for Control Structures in PHP?
There are many times that this alternative syntax is excellent for improving legibility (for both PHP and HTML!) in situations where you have a mix of them. Interface templates are very often in need of this. This is very useful when one person is programmer and an another person is modifying the HTML. Clear separation in such cases is extremely useful. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to use an Alternative Syntax for Control Structures in PHP?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Alternative to change the mouse speed and control of Pirates of Black Cove | Gaharwar | Video Games | 5 | 02-09-2011 11:39 AM |
| Can I use Belkin Bluetooth receiver as an alternative for volume control | Dinesh Dubey | Windows Software | 5 | 07-03-2011 12:01 AM |
| How does a class vary from Structures ? | Chellam | Software Development | 4 | 30-12-2010 08:20 AM |
| ATi Catalyst 9.1 or 9.2 with an alternative for Catalyst Control Center | Gaige | Monitor & Video Cards | 6 | 03-06-2010 12:03 AM |
| Pointer to an array of structures | Zool | Software Development | 3 | 13-05-2009 11:51 PM |