I was running the following PHP code using addition? -


this question has answer here:

  1. this code:

        <?php     $a = "4 fox , 3 cows"; // simple string     $b = 22;     echo $ab = $a + $b;     echo "output::".$ab;     ?>' 

    output: first index being read 26 logic behind this..? instead should error..

2.another example:

     <?php         $a = "four fox , 3 cows"; // simple string         $b = 22;         echo $ab = $a + $b;         echo "output::".$ab;         ?>'    output:    22    logic behind this..? 

you should type juggling, php it's best accommodate ability transform type casting on fly, using + operator in php meant 2 numbers whether integer, decimal, etc.

since strings don't have integral value, when use + operator use first part of string can make valid integer.

since example starts "4 " truncates else , turns 4 integer making 4+22 26.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -