/** * First Leaf * - returns the first non-array element (singular or object). * - handy when you're not sure whether information has been stored * as a singular value ('item') or 1-element array (0=>'item'). * - the key() function gives us the first key in the array. * - uses recursion to go deeper if necessary; if that's not * what you want, you may need a different solution. */ public static function first_leaf ( $value ) { return !is_array( $value ) ? $value : first_leaf( $value[key($value)] ); }