Home | Store | osCommerce Tutorials

PHP isset() Function

The PHP isset() function is always used in osCommerce codes.

The PHP isset() function will determine if a variable is set and is not NULL.

Notes for PHP isset() function:

  • Returns TRUE if the variable exists and has value other than NULL.
  • Remember that an empty string is not null.
  • The result may sometimes expect differently with PHP version 4 and 5.

PHP isset() Function Example 1:

<?php

// The value of $cPath come from Hardware
$cPath = "1";

if (isset($cPath)) {

// if the $cPath variable is set and is not null, the codes here will be executed.
echo 'The value of $cPath is set and the value is: ' . $cPath;

} else {

// if the $cPath variable is NOT set, the codes here will be executed.
echo 'The value of $cPath is NOT set';

}

?>

The output of the above PHP isset() function example 1 should look like:

Thee value of $cPath is set and the value is: 1

PHP isset() Function Example 2:

<?php

// The value of $cPath come from osCommerce homepage.
// The value of $cPath is now empty.
$cPath = "";

if (isset($cPath)) {

// if the $cPath variable is set and is not null, the codes here will be executed.
echo 'The value of $cPath is set and the value is: ' . $cPath;

} else {

// if the $cPath variable is NOT set, the codes here will be executed.
echo 'The value of $cPath is NOT set';

}

?>

The output of the above PHP isset() function example 2 should look like:

The value of $cPath is set and the value is:

Although the value of $cPath is empty, the isset() function still return TRUE.

This is the end of PHP isset() function for osCommerce shop.