|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-11-12 14:34 UTC] olito24 at gmx dot de
[2004-12-10 20:06 UTC] nlopess@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 11:00:01 2025 UTC |
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