« 2007年07月 | メイン | 2007年11月 »

2007年08月 アーカイブ

2007年08月15日

お盆のリンクシンク

ビアガーデン ベランダ

ビールあります
スモーカーかんげい

2007年08月21日

リンクシンク生放送中(`・ω・´)
http://ustream.tv/channel/linkthink
生大好き!

2007年08月29日

PHP Idiosyncrasies #2

"Pictures speak a thousand words", so let's jump straight into the code again:

  <?php
  $test_data = array(
    '1' => '1',
    'a' => 'a',
    '2' => '2',
    'b' => 'b',
    '00' => '00',
  );

  $test_data = array_flip($test_data);
  var_dump($test_data);

And the output:

  array(5) {
    [1]=>
    int(1)
    ["a"]=>
    string(1) "a"
    [2]=>
    int(2)
    ["b"]=>
    string(1) "b"
    ["00"]=>
    string(2) "00"
  }

Notice that numerical keys - actually only those matching ^(0|[1-9
][0-9]*)$
- have had there type changed from string to int.

And now for the important point:

  # Example 1
  var_dump(array_slice($test_data, 1));

  # Example 2
  array_shift($test_data);
  var_dump($test_data);

Both of the above examples produce:

  array(4) {
    ["a"]=>
    string(1) "a"
    [0]=>
    int(2)
    ["b"]=>
    string(1) "b"
    ["00"]=>
    string(2) "00"
  }

What's this? 2 => "b" has just been changed to 0 => "b"?
Yep, that's right. PHP will go ahead and renumber any integer keys when slicing and dicing arrays - even though it was given as a string in the first place.

BlogPet

リラックマ

About 2007年08月

2007年08月にブログ「LINKTHINKTANK」に投稿されたすべてのエントリーです。過去のものから新しいものへ順番に並んでいます。

前のアーカイブは2007年07月です。

次のアーカイブは2007年11月です。

他にも多くのエントリーがあります。メインページアーカイブページも見てください。