php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #26347 array_element function.
Submitted: 2003-11-21 06:11 UTC Modified: 2004-08-25 10:36 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: technophreak at gammae dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.3.2 OS: all
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-11-21 06:11 UTC] technophreak at gammae dot com
Description:
------------
There should be a function used to simply return element [n] of an array. This will allow to return the value of an array by simply specifying the key or element to be returned. list() or any other function can do this.

if a such function alredy exist please let me know. I didnt find it.

Reproduce code:
---------------
Sample code of what function should do.

function array_element($array array,$element mixed){
  return $array[$element];
}


here is an example of why that would be useful.

If i dont want to write two lines to get a hostname from a url.

$myhost = array_element(parse_url($someurl),"host");

INSTEAD OF

$host_info = parse_url($someurl);
$myhost = $host_info["host"];

Also.. there are many things that the list() function cannot do ... an array_element() function would be very useful in any situation where the array would be the result of another function ..

There are numerous examples where I would have used that and I am sure that a lot of people would be looking for suck feature.

Same idea for an array_put() function but array_merge() does the same.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-21 06:13 UTC] technophreak at gammae dot com
sorry for the typo, I meant SUCH, not SUC* ...
 [2004-04-03 11:43 UTC] derick@php.net
You can use those two lines of code just fine. Marking this "won't fix".

regards,
Derick
 [2004-08-25 10:28 UTC] leszek at dubiel dot pl
Yes -- we can use these two lines of code, but I thought php was build to be simple -- why does it have so many other functions? I think this should be opened.
 [2004-08-25 10:36 UTC] derick@php.net
Perhaps we should also add a show_me_a_forum() then?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 21:01:33 2024 UTC