FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » arrays with holes
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: arrays with holes [message #176780 is a reply to message #176775] Mon, 23 January 2012 22:59 Go to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma:
Senior Member
.oO(Álvaro G. Vicario)

> If array keys are meaningful but unknown, I can't figure out many other
> ways to find for the nth element than array_splice(). [...]

I think you could also use array_keys() and then get the nth key.
Something like this (untested and without any error checking):

function getElement(array $array, $index) {
$keys = array_keys($array);
return $array[$keys[$index]];
}

Wrap the whole thing into your own array class and you could even do

$foo = $array['foo'];
$bar = $array[5];

where the first statement would directly return the element with the key
'foo' and the second one the element at the 6th position, regardless of
the keys (using the function from above).

Just a quick idea.

Micha

--
http://mfesser.de/blickwinkel
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Parsing .css files with php: Cons?
Next Topic: Open Source Customization
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 04:39:26 GMT 2024

Total time taken to generate the page: 0.04782 seconds