php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11524 shifting or popping array with leading or trailing empty elements
Submitted: 2001-06-17 18:32 UTC Modified: 2004-07-20 19:07 UTC
From: jmroth at iip dot lu Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.5 OS: Linux 2.2.16
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jmroth at iip dot lu
New email:
PHP Version: OS:

 

 [2001-06-17 18:32 UTC] jmroth at iip dot lu
Let's say I have this string: 
/FAQ/ 
(a URI, actually) 
An explode action (delim is /)with a resulting count of the array reveals 3 elements. 
After an array_shift or array_pop, the count goes to 1. 3-1=1?

$uri = strtolower(preg_replace("/[^a-zA-Z0-9\/]/","",$HTTP_SERVER_VARS["REQUEST_URI"]));
$uri = explode("/", $uri); // make it an array
echo count($uri);
$uri = array_shift($uri); // delete first value which is always empty
echo count($uri);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-18 15:25 UTC] cardinal@php.net
Please see the man pages for array_shift and array_pop.

Both functions return the element they removed, not the
modified array.  So, $uri = array_shift($uri); is returning
an empty string, the first element of the array.

 [2004-07-20 19:07 UTC] jmroth at iip dot lu
ok
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC