is_scalar

Views: 2 Last modified: July 31st, 2011 Comments: 0

The function is_scalar() will check if the variable holds a scalar value. This means, it checks if the variable is a integer, boolean, float or string.
It returns false if the variable is not scalar, if it is, it will return true

// Return: Scalar
if (is_scalar('Hello World')) echo 'Scalar'; else echo 'Not scalar';

// Return: Not scalar
if (is_scalar(array())) echo 'Scalar'; else echo 'Not scalar';

// Return: Not scalar
if (is_scalar(new stdClass())) echo 'Scalar'; else echo 'Not scalar';

// Return: Scalar
if (is_scalar(582.58)) echo 'Scalar'; else echo 'Not scalar';

// Return: Scalar
if (is_scalar(true)) echo 'Scalar'; else echo 'Not scalar';

// Return: Scalar
if (is_scalar(35)) echo 'Scalar'; else echo 'Not scalar';

Result:

Scalar
Not scalar
Not scalar
Scalar
Scalar
Scalar
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
    Bluehost

    Mail this!

    To: From:Sum {2+7} =  
    Anything to add ?

        You must be logged in to post a comment.