php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11351 array_shift breaks numeric index key association in PHP4.05
Submitted: 2001-06-08 05:48 UTC Modified: 2001-07-22 13:05 UTC
From: jason at sitepoint dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.5 OS: RH6.2
Private report: No CVE-ID: None
 [2001-06-08 05:48 UTC] jason at sitepoint dot com
Hi guys,

This is perhaps not a bug, more an anomaly, perhaps.

<?

$my_array = array
(
    0 => "Service ID",
    1 => "Daily News Feed",
    2 => "Search For Your Site",
    3 => "Instant Access to Experts",
    4 => "Submit to the Search Engines",
    5 => "Link Checker",
    6 => "Free Email @yourdomain.com",
    7 => "Generate Meta Tags",
    9 => "HTML Toolbox",
    10 => "Shrink your graphics",
    12 => "Cheap Domain Registration",
    13 => "Targetted Traffic",
    14 => "Community Forums",
    15 => "Log Analysis",
    20 => "Free, Color, Business Cards",
    16 => "Royalty Free Images",
    17 => "Search Engine Optimizer",
    18 => "Search Engine Starter",
    19 => "Web Server Monitor",
    21 => "FlashBlaster",
    22 => "EchoTools",
    23 => "SitePoint Tip Feed",
    24 => "Website Appraisal & Benchmark Service"
);

print_r($my_array);
array_shift($my_array);
print_r($my_array);

?>

produces the following result (notice that there is no item #8 or #11 in the first list).  Notice that all I want to do is remove the first item, whilst keeping the key integrity.  What happens is that the data is reindexed and the keys are lost.

Perhaps this is desired behaviour?  Just thought I'd pop you an email anyway.

Array
(
    [0] => Service ID
    [1] => Daily News Feed
    [2] => Search For Your Site
    [3] => Instant Access to Experts
    [4] => Submit to the Search Engines
    [5] => Link Checker
    [6] => Free Email @yourdomain.com
    [7] => Generate Meta Tags
    [9] => HTML Toolbox
    [10] => Shrink your graphics
    [12] => Cheap Domain Registration
    [13] => Targetted Traffic
    [14] => Community Forums
    [15] => Log Analysis
    [20] => Free, Color, Business Cards
    [16] => Royalty Free Images
    [17] => Search Engine Optimizer
    [18] => Search Engine Starter
    [19] => Web Server Monitor
    [21] => FlashBlaster
    [22] => EchoTools
    [23] => SitePoint Tip Feed
    [24] => Website Appraisal & Benchmark Service
)
Array
(
    [0] => Daily News Feed
    [1] => Search For Your Site
    [2] => Instant Access to Experts
    [3] => Submit to the Search Engines
    [4] => Link Checker
    [5] => Free Email @yourdomain.com
    [6] => Generate Meta Tags
    [7] => HTML Toolbox
    [8] => Shrink your graphics
    [9] => Cheap Domain Registration
    [10] => Targetted Traffic
    [11] => Community Forums
    [12] => Log Analysis
    [13] => Free, Color, Business Cards
    [14] => Royalty Free Images
    [15] => Search Engine Optimizer
    [16] => Search Engine Starter
    [17] => Web Server Monitor
    [18] => FlashBlaster
    [19] => EchoTools
    [20] => SitePoint Tip Feed
    [21] => Website Appraisal & Benchmark Service
)

By the way, did you see our "Building a DataBase Drive Website Using PHP and MySQL" is now the feature article on the front page of MySQL.com?  Would PHP.net like to consider something similar?

http://www.mysql.com/articles/ddws/index.html
http://www.sitepoint.com/article.php/228

Cheers,

Jason.

___________________________________

Jason Donald
Chief Technology Officer/Co-Founder
SitePoint - Master the Web

e: jason@sitepoint.com
w: www.sitepoint.com
p: +613 9495 6600
f: +613 9495 6611
___________________________________

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-08 05:56 UTC] jason at sitepoint dot com
This is perhaps more appropriate for posting to the list, please excuse my form. :)


<?

$my_array = array
(
    101 => "Item A",
    213 => "Item B",
    348 => "Item C",
    967 => "Item D",
);

print_r($my_array);
array_shift($my_array);
print_r($my_array);

?>


Produces:

Array
(
    [101] => Item A
    [213] => Item B
    [348] => Item C
    [967] => Item D
)
Array
(
    [0] => Item B
    [1] => Item C
    [2] => Item D
)
 [2001-06-08 14:33 UTC] sniper@php.net
Did this work in 4.0.4pl1?
Does it work with the latest RC sources:

http://www.php.net/~andi/php-4.0.6RC3.tar.gz

--Jani

 [2001-07-22 13:05 UTC] andy@php.net
no feedback after 40+ days.
 [2011-11-14 18:01 UTC] nikic@php.net
Automatic comment from SVN on behalf of nikic
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=319186
Log: Fix typo

--
Provided by anonymous #11351 ()
 [2011-12-05 22:31 UTC] frozenfire@php.net
Automatic comment from SVN on behalf of frozenfire
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=320468
Log: Changed the description of PDO::FETCH_KEY_VALUE to match actual behaviour (requiring the result set to have exactly two columns). Closes bug #55053.
--
Provided by anonymous #11351 ()
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 21:01:30 2024 UTC