php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55095 idea/request for new array_function
Submitted: 2011-06-30 23:42 UTC Modified: 2011-07-01 03:02 UTC
From: anticom at hotmail dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.6 OS: Windows Vista 32Bit
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: anticom at hotmail dot de
New email:
PHP Version: OS:

 

 [2011-06-30 23:42 UTC] anticom at hotmail dot de
Description:
------------
I realy would prefer a function for associative arrays, enableing to get an index-specific key.

This would be usefull especialy for big array's, so you have to iterate through them, to get a specific key. The other advantage would be, that you could iterate through the array manually with a for-loop, without having to store all the key's in a temporary array using array_keys()

Test script:
---------------
<?php
$arr = array("foo" => 'bar', "secondFoo" => 'anyval');
echo array_getKeyAt($arr, 1);
?>

Expected result:
----------------
output would be:
secondFoo

Actual result:
--------------
[function not implemented yet afaik]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-01 00:35 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-07-01 00:35 UTC] rasmus@php.net
echo array_keys($arr)[1];  // PHP 5.4
 [2011-07-01 00:40 UTC] rasmus@php.net
Or if you are worried about the size of the array, just slice it. This works 
nicely in older PHP versions as well:

// Get 1 key starting at position 2 of $arr
echo key(array_slice($arr, 2, 1, true));
 [2011-07-01 03:02 UTC] anticom at hotmail dot de
Thank you rasmus :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 20:01:35 2025 UTC