Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Basics Unit Converter Integers

György Varga
György Varga
19,198 Points

is_* function

Hi!

I wanna examine that a variable is an integer or a string, but echo is_string( $num_one ); doesnt return any value. No 0 or 1. But the echo is_int( $num_one ); is returning a 1 that is true.

Is there no value return if a is_*function is fale?

Thank you!

https://w.trhou.se/8j2ck3mmjq

1 Answer

Leandro Botella Penalva
Leandro Botella Penalva
17,618 Points

Hi Varga,

According to the PHP manual, "A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values."

If you still want to see 0 or 1 using echo you can convert the boolean to integer like this:

echo (int)is_string( $num_one );