Hi all..
If I have a variable like:
$var = 1234567890;
How can I return the number of char's in that variable?
As well, while we're at it.. Am I correct in that you don't have to specify what type of variable you are defining, but php does it for you automatically?
What if I wanted to, could I?
Could I do something like:
int $var = 1234567890;
Thanks
David
Return number of characters in a variable
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Code: Select all
$var = (int)6544645;
$var = (float)6544645;or later on in the script
Code: Select all
settype($var, "string");or:
Though jshpro2's suggestion is the most efficient and is the "proper" way.
But in PHP, using quotes signifies that it is a string, no quotes and numerics signifies it is an int, numerics with a decimal signifies it is a float.
Code: Select all
$int = intval(123);
$str = strval('123');But in PHP, using quotes signifies that it is a string, no quotes and numerics signifies it is an int, numerics with a decimal signifies it is a float.