PHP:它是动态的东西还是其他任何东西

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";
  }

First of all, it doesn't print '0', but lowercase 'o'. Try this:

$string = 'abc';
echo $string['omgwhysuchkeyworks'];

It will print 'a'. That is because it seems in PHP when you try any key (other than numeric) on string variable it will return the first character of the string. That's also why isset($a['b']['ok']) returns true.

And it might be an issue of the PHP version. Perhaps on newer version it will work as intended (it will write 'else')

It prints else. 'ok' is no array index but a value on index 'b' of array $a:

Array
(
    [b] => okokokok
)

See http://ideone.com/50EhGW

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".

$a = Array('b' = > 'okokokok');
  if ( isset( $a['b']['ok'] ) ) {
      echo $a['b']['ok']; // Print 0
  } else {
      echo "else";
  }

When you have a string ,you can treat it as array. its indexes would be numerical, starting from zero to string length minus one. But if you try to pass a string as index (ok in this case) , PHP tries to convert it to integer , evaluates it as zero(intval('ok')). On systems with php 5.4, it treat differently and checks the key itself and doesn't do the converting .So, in one system it may print else and on the other it prints o.