note 71786 rejected from function.pos by nlopess

From: Date: Sun, 17 Dec 2006 19:25:49 +0000
Subject: note 71786 rejected from function.pos by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-120691@lists.php.net to get a copy of this message
Note Submitter: randallgirard at hotmail dot com ---- Logically, pos($array) should give the numeric offset of the array's internal pointer. Either or, a new routine should be added for example array_numeric_offset($array), if desired that pos remain an alias of current() for current software compadibility. There should also be two routines added into the engine as well, named seek($array, $pos) and seek_key($array, $key), which logically would seek the internal pointer to an offset or key. This would greatly improve on Array functionality, and open many doors to new advanced structures and algorithms, respectively within the PHP engine. Actually, I have written routines to do just that for use in my CMS I'm working on, however they are inefficient and a language level implementation of these routines would be great and very much appreciated. However, I still lack the ability to look up the current pos/offset, again without looping through the entire array and comparing the current key. Or, perhaps am I missing something? The idea here, is for example when using routines like array_splice, where it takes an offset rather than a key. hence in an array like: array(1 => 'first', '0' => 'second'), clearly $array[0] would reference the second value as it should, however array_splice sort of doesn't have much useability without this type of functionality. This can be very usefull when doing advanced looping, manipulating and splicing of arrays, etc... As when you splice something in or strip values, the internal array is abviously reset, and you then need to seek to a new position (perhaps a quick math equation to seek either after or before the added or stripped values, as per algorithm of course) Personally I prefer engines like Perl, but my clients want PHP and I'm kind of stuck here. In my experience, I have found many weak points within PHP, and these are a few ideas I've come to which would add great functionality into PHP structures... I don't know how to get these ideas to the dev team, nor do really I care... I'm sure someone will do it for me if they see the need for these ;D Personally, I would rather see PHP evolve into a more modern scripting engine, as it is still in a very basic stage, especially in the OOP, logical uses of routines and math, references, and I can go on and on.... I have ideas stacked apon ideas, and would be glad to share more ;D

« previous php.notes (#120691) next »