statement

statement

PHP Variable Assignment Within If Statement

Sunday, June 7, 2009 - 11:43

The usual practice when checking for the return value of functions is to run the function and store the value in a variable, and then test that variable. Here is an example of that process using the strstr() function.

1
2
3
4
5
6
7
$string = 'abcde';
$var = strstr($string, 'f');
if ( false !==  $var ) {
    var_dump($var);
} else {
    var_dump($var);
}

This code will output "bool(false)" as that was the return value of the strstr() function.

Category: 

Using PHP implode() To Construct Strings

Thursday, June 4, 2009 - 10:33

If you are constructing a simple string from a set of variables contained in an array then you can use the implode function to convert the array into a string. The implode() function takes two parameters. The first is the glue that is used to join the items in array together and the second is the array to use. Here is a trivial example of implode() in action.

Category: 

Alternate If Statements In PHP

Sunday, January 20, 2008 - 21:10

If you have programmed in PHP for any amount of time then you will be farmiliar with the if statement. The syntax is as follows:

Category: