11.1. Data Types, Constants, and Variables

These functions check the status of a variable, change its type, or return a value as a particular data type.

value constant(string name)

Use constant (Listing 11.1) to fetch the value of a constant. This offers the ability to specify a constant with a variable.

Listing 11.1. constant
<?php
    function getDatabaseProperty($property)
    {
        return(constant("DATABASE_$property"));
    }

    define("DATABASE_HOST", "localhost");
    define("DATABASE_USER", "httpd");
    define("DATABASE_PASSWORD", "");
    define("DATABASE_NAME", "freetrade");

    print(getDatabaseProperty('HOST'));
?>

boolean ctype_alnum(string text)

The ctype_alnum function tests whether every character in the given string is in the set of all digits and letters, ...

Get Core PHP Programming, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.