mrkrstphr
1/18/2015 - 7:31 PM

wtf am i doing wrong?

wtf am i doing wrong?

$ php test.php
array(4) {
  [0] =>
  int(123)
  [1] =>
  string(3) "abc"
  [2] =>
  int(890)
  [3] =>
  string(15) "20001020-0123XR"
}
array(4) {
  [123] =>
  int(123)
  'abc' =>
  int(123)
  [890] =>
  int(123)
  '20001020-0123XR' =>
  int(123)
}
<?php
$provider = [
    123 => 123,
    'abc' => 123,
    890 => 123,
    '20001020-0123XR' => 123
];

var_dump(array_keys($provider));
var_dump($provider);

What am I doing wrong?

Why does PHP cast numeric string keys to integer equivalents?

Nevermind...

Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.

Source: http://php.net/manual/en/language.types.array.php

H8 @ PHP.