I am trying to understand the truthiness of strings in PHP. I thought it might be like other scripting language like Javascript or Python.
> var_dump((bool)"");
bool(false);
> var_dump((bool)"hello");
bool(true);
Okay, makes sense.
Then I tried
> var_dump((bool)"0");
bool(false);
Really? That's weird. I guess PHP tries to parse the string as a number first. So this should also be false
> var_dump((bool)"00");
bool(true);
Huh?!? I am really confused, and would like to know what makes a string truthy or not.
I haven't been able to find anything so far.
See the docs for converting to boolean: