In Java when I declare a variable int A; by default it assigns 0 to the variable A. But in PHP if I declare a variable as $A the default value of it sets as null. Instead of assigning it as $A=0; are there any ways available to set a default value as 0 for variable $A, as I did in Java?
You can set its type. Since you don't wana initialize to 0, setting type to integer will do that for you.
<?php
settype($foo, "integer");
echo $foo;
?>
Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With