30秒学会 PHP 片段 · 2018年5月26日

30秒学会 PHP 片段 – head

Returns the head of a list.

Use reset() to return the first item in the array.

代码实现

function head($items)
{
  return reset($items);
}

使用样例

head([1, 2, 3]); // 1