/** * Calls the method named by $methodName on first value in the collection. Any extra arguments passed to invoke will be * forwarded on to the method invocation. * * @param Traversable|array $collection * @param string $methodName * @param array $arguments * @return array */ function invoke_first($collection, $methodName, array $arguments = array()) { Exceptions\InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); Exceptions\InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 2); foreach ($collection as $index => $element) { $value = null; $callback = array($element, $methodName); if (is_callable($callback)) { return call_user_func_array($callback, $arguments); } } return null; }