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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC