#11524 [Bgs->Csd]: shifting or popping array with leading or trailing empty elements

From: Date: Tue, 20 Jul 2004 17:07:33 +0000
Subject: #11524 [Bgs->Csd]: shifting or popping array with leading or trailing empty elements
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-63173@lists.php.net to get a copy of this message
 ID:               11524
 User updated by:  jmroth at iip dot lu
 Reported By:      jmroth at iip dot lu
-Status:           Bogus
+Status:           Closed
 Bug Type:         Arrays related
 Operating System: Linux 2.2.16
 PHP Version:      4.0.5
 New Comment:

ok


Previous Comments:
------------------------------------------------------------------------

[2001-06-18 15:25:22] 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.


------------------------------------------------------------------------

[2001-06-17 18:32:12] 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);


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=11524&edit=1


Thread (1 message)

  • jmroth at iip dot lu
  • Unknown Message
    • jmroth at iip dot lu
« previous php.bugs (#63173) next »