note 62042 modified in function.array-keys by danbrown
| From: | danbrown@php.net | Date: | Wed, 25 Aug 2010 01:49:04 +0000 |
| Subject: | note 62042 modified in function.array-keys by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172010@lists.php.net to get a copy of this message | ||
might be worth noting in the docs that not all associative (string) keys are a like, output of the
follow bit of code demonstrates - might be a handy introduction to automatic typecasting in php for
some people (and save a few headaches):
<?php
$r = array("0"=>"0","1"=>"1",""
=>"2"," "=>"3");
echo 'how php sees this array:
array("0"=>"0","1"=>"1",""
=>"2"," "=>"3")',"\n-----------\n";
var_dump($r); print_r($r); var_export($r);
echo "\n-----------\n",'var_dump("0","1","","
") = ',"\n-----------\n";
var_dump("0","1",""," ");
?>
OUTPUTS:
how php sees this array:
array("0"=>"0","1"=>"1",""
=>"2"," "=>"3")
-----------
array(4) {
[0]=>
string(1) "0"
[1]=>
string(1) "1"
[""]=>
string(1) "2"
[" "]=>
string(1) "3"
}
Array
(
[0] => 0
[1] => 1
[] => 2
[ ] => 3
)
array (
0 => '0',
1 => '1',
'' => '2',
' ' => '3',
)
-----------
var_dump("0","1",""," ") =
-----------
string(1) "0"
string(1) "1"
string(0) ""
string(1) " "
--was--
might be worth noting in the docs that not all associative (string) keys are a like, output of the
follow bit of code demonstrates - might be a handy introduction to automatic typecasting in php for
some people (and save a few headaches):
$r = array("0"=>"0","1"=>"1",""
=>"2"," "=>"3");
echo 'how php sees this array:
array("0"=>"0","1"=>"1",""
=>"2"," "=>"3")',"\n-----------\n";
var_dump($r); print_r($r); var_export($r);
echo "\n-----------\n",'var_dump("0","1","","
") = ',"\n-----------\n";
var_dump("0","1",""," ");
OUTPUTS:
how php sees this array:
array("0"=>"0","1"=>"1",""
=>"2"," "=>"3")
-----------
array(4) {
[0]=>
string(1) "0"
[1]=>
string(1) "1"
[""]=>
string(1) "2"
[" "]=>
string(1) "3"
}
Array
(
[0] => 0
[1] => 1
[] => 2
[ ] => 3
)
array (
0 => '0',
1 => '1',
'' => '2',
' ' => '3',
)
-----------
var_dump("0","1",""," ") =
-----------
string(1) "0"
string(1) "1"
string(0) ""
string(1) " "
http://php.net/manual/en/function.array-keys.php