Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Using the Ternary Operator
Nov 01, 2011 @ 14:43:35

On PHPMaster.com today there's a new tutorial showing the use of a sometimes overlooked (but very handy) alternate syntax that PHP includes - the ternary operator, a short-hand if/else.

You’re probably already familiar with PHP’s if statement. It’s very similar to its counterparts in many other programming languages and represents one of the most fundamental concepts in programming. [...] But there’s a way to build on this concept and increase your $coolFactor a bit in the process. Allow me to introduce you to the ternary operator, which serves as a shorthand notation for if statements.

They introduce the ternary operator's syntax, the ":" and "?" operators and includes a few pieces of code showing its use. Thankfully they also include a warning - don't overuse or abuse it...and especially don't nest them - that just leads to headaches.

tagged: ternary if else shorthand alternate syntax

Link:

PHP 10.0 Blog:
syntax I miss in PHP
Aug 24, 2009 @ 14:40:34

In this new post to the PHP 10.0 blog Stas mentions some of the other syntax options he's like to see in PHP including:

  • a()() - When a() returns a callable object (such as a closure) the second set of brackets would call it.
  • foo(1,2,,4) - Syntax to skip a parameter in a call, which then will be substituted with the default as defined by the function.
  • $a = ["a", "b" => "c"]; - I’d really like to have short array syntax. Yes, I know it was rejected so many times already, but I still like it.

Be sure to catch some of the good amount of comments with options from others about Stas' suggestions.

tagged: alternate additional syntax

Link:

WebReference.com:
How To Create Alternating Row Colors in PHP
Jun 20, 2007 @ 16:12:00

WebReference.com has a simple new tutorial today showing how to create alternating table rows in the output for your application.

Almost every database driven Web site uses alternating row colors when displaying a list of records, a concept used all over the Internet. You've seen it used, you like it, and now you want to do it yourself. But you're not sure how to accomplish it. Well you've come to the right place. I'm going to discuss the basic idea behind achieving this and give some concrete examples demonstrating different ways to implement it.

Their script loops through the information (numbers in their case) and checks, using the modulus operator to check and see which of the CSS styles it should apply to the div. To give a range of possibility, they also show how to do it with a while loop instead of a for to do a little benchmarking of the methods.

tagged: alternate row color table forloop whileloop css alternate row color table forloop whileloop css

Link:

WebReference.com:
How To Create Alternating Row Colors in PHP
Jun 20, 2007 @ 16:12:00

WebReference.com has a simple new tutorial today showing how to create alternating table rows in the output for your application.

Almost every database driven Web site uses alternating row colors when displaying a list of records, a concept used all over the Internet. You've seen it used, you like it, and now you want to do it yourself. But you're not sure how to accomplish it. Well you've come to the right place. I'm going to discuss the basic idea behind achieving this and give some concrete examples demonstrating different ways to implement it.

Their script loops through the information (numbers in their case) and checks, using the modulus operator to check and see which of the CSS styles it should apply to the div. To give a range of possibility, they also show how to do it with a while loop instead of a for to do a little benchmarking of the methods.

tagged: alternate row color table forloop whileloop css alternate row color table forloop whileloop css

Link:

MSBWare.com:
Alternating Row Colors
May 02, 2007 @ 21:13:00

Sometimes, a simple approach is the best. That's what Michael Berman went with in this light and easy tutorial. It focuses on the creation of an "alternating rows" script with PHP.

This concept is used all over the internet. Almost every database driven website uses alternating row colors when displaying a list of records. You've seen it used, you like it, and now you want to do it yourself. But, you're not sure how to accomplish it. Well you've come to the right place. I'm going to discuss the basic idea behind achieving this and give some concrete examples demonstrating different ways to implement it.

The example code show how to alternate between two colors - white and grey - for the background of a series of DIVs. He even includes a series of tests to show which method of switching them out would be faster (while loop, for loop, etc).

tagged: alternate row color loop benchmark tutorial alternate row color loop benchmark tutorial

Link:

MSBWare.com:
Alternating Row Colors
May 02, 2007 @ 21:13:00

Sometimes, a simple approach is the best. That's what Michael Berman went with in this light and easy tutorial. It focuses on the creation of an "alternating rows" script with PHP.

This concept is used all over the internet. Almost every database driven website uses alternating row colors when displaying a list of records. You've seen it used, you like it, and now you want to do it yourself. But, you're not sure how to accomplish it. Well you've come to the right place. I'm going to discuss the basic idea behind achieving this and give some concrete examples demonstrating different ways to implement it.

The example code show how to alternate between two colors - white and grey - for the background of a series of DIVs. He even includes a series of tests to show which method of switching them out would be faster (while loop, for loop, etc).

tagged: alternate row color loop benchmark tutorial alternate row color loop benchmark tutorial

Link:


Trending Topics: