ID: 30768
Updated by: [EMAIL PROTECTED]
Reported By: olito24 at gmx dot de
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: debian linux 2.4.21-1-686
PHP Version: 4.3.9
New Comment:
Yep, you are right. and the manual states:
"All numerical array keys will be modified to start counting from zero
while literal keys won't be touched."
So there is no problem in the documentation. closing..
Previous Comments:
------------------------------------------------------------------------
[2004-11-12 14:34:49] olito24 at gmx dot de
arrays don't take numerical keys as strings, they are always casted
into integers. so that's the problem but not a bug.
------------------------------------------------------------------------
[2004-11-12 14:15:39] olito24 at gmx dot de
Description:
------------
the array that is to be passed to array_unshift() has strings as its
keys. if a key is a number, array_unshift does not keep the type string
for this key in the resulting array. in the following example, the top
level key [1] should in fact be [181050] (as a string). it is index [1]
because the first entry is [0], which in fact is meant to be an integer
value. an example how i used unshift to insert the first entry in the
already existing array:
array_unshift ($relativeCampaignData_A, array ('id' => 0, 'title' =>
'k.A.'));
(usually the [id] entries are strings, the first top array element is
an exception.
the resulting array is:
Array
(
[0] => Array
(
[id] => 0
[title] => k.A.
)
[e94a5a] => Array
(
[id] => e94a5a
[title] => example1
)
[0f298f] => Array
(
[id] => 0f298f
[title] => example2
)
[1] => Array
(
[id] => 181050
[title] => thisKeyIsTheError
)
[1cfb8b] => Array
(
[id] => 1cfb8b
[title] => example3
)
)
before using unshift index [1] was associative index [181050] as a
string by using strval.
Reproduce code:
---------------
$array = array('123abc' => array('id' = '123abc', 'title' =
'example2'), '456789' => array('id' = '456789', 'title' =
'errorexample'));
print_r ($array);
echo '<br><br>';
array_unshift ($array, array('id' => 0, 'title' => 'example1'));
print_r ($array);
Expected result:
----------------
$array [0] = array
$array ['123abc'] = array
$array ['456789'] = array
Actual result:
--------------
$array [0] = array
$array ['123abc'] = array
$array [1] = array
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30768&edit=1