Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP : is it dynamich thing or any thing else

Tags:

arrays

php

isset

Anyone can explain it why is it true

  $a = Array('b' = > 'okokokok');
  if ( isset( $a['b']['ok'] ) ) {
      echo $a['b']['ok']; // Print 0
  } else {
      echo "else";
  }
like image 908
Manish Trivedi Avatar asked Dec 10 '25 21:12

Manish Trivedi


1 Answers

This was for backward compatibility with PHP 4 (see PHP Bug #29883). When casting a string to an integer, and the string is not a valid integer, it becomes 0 (zero). The letter "o" is printed because that is the character at offset 0 in the string.

In PHP 5.4, the behavior intentionally changed (see PHP Bug #60362); that PHP version instead prints "else".

like image 132
PleaseStand Avatar answered Dec 13 '25 12:12

PleaseStand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!