Access PHP array element with a function?

后端 未结 5 889
[愿得一人]
[愿得一人] 2020-12-30 04:41

I\'m working on a program that uses PHP\'s internal array pointers to iterate along a multidimensional array. I need to get an element from the current row, and I\'ve been d

5条回答
  •  無奈伤痛
    2020-12-30 05:03

    I very much doubt there is such a function, but it's trivial to write

    function getvalue($array, $key)
    {
      return $array[$key];
    }
    

    Edit: As of PHP 5.4, you can index array elements directly from function expressions, current($arr)['item'].

提交回复
热议问题