#21556 closed enhancement (wontfix)
Function to return value of an array element taking the array and a key as input
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
PHP has a syntactical issue with a construct like the following:
$value = return_array_fun()[$key];
where return_array_fun() is a function returning an array as output.
One is forced to rewrite it as
$temp_array = return_array_fun(); $value = $temp_array[$key];
It would be nice to have a function in WordPress that makes this simple. Here's the one-liner:
/** * Get the value of an element in an array */ function array_get_value( $array, $key ) { return $array[$key]; }
I didn't create a separate diff file for this.
Change History (5)
#2
in reply to:
↑ 1
@
12 years ago
Replying to wonderboymusic:
I don't think you need an accessor function like that, it's too much reflection.
Agreed. Maybe I should be talking to the guys at php.net project to resolve the syntactic issues. :)
Note: See
TracTickets for help on using
tickets.
I don't think you need an accessor function like that, it's too much reflection. Reading values is like 1000x's faster than reading the return value of a function call in PHP. And instead of setting
$value = $arr[$key]
, just refer to it as$arr[$key]
unless you act on it by callingtrim()
or something