[wp-trac] [WordPress Trac] #21556: Function to return value of an array element taking the array and a key as input

WordPress Trac wp-trac at lists.automattic.com
Sun Aug 12 16:36:24 UTC 2012


#21556: Function to return value of an array element taking the array and a key as
input
-------------------------+-----------------------------
 Reporter:  gkb6891      |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:  has-patch
-------------------------+-----------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21556>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list