/** * Generates a table with a header column and a value column from the given array. * * @param mixed $value * @param string $title [optional] * @param int $maxDepth [optional] Max. recursion depth. * @param array $excludeProps [optional] Exclude properties whose name is on the list. * @param bool $excludeEmpty [optional] Exclude empty properties. * @param int $depth [optional] For internal use. * @return string */ public static function grid($value, $title = '', $maxDepth = 1, $excludeProps = [], $excludeEmpty = false, $depth = 0) { if (is_null($value) || is_scalar($value)) { return self::toString($value); } if ($depth >= $maxDepth) { return "<i>(...)</i>"; } if (is_object($value)) { if (method_exists($value, '__debugInfo')) { $value = $value->__debugInfo(); } else { $value = get_object_vars($value); } } if ($title) { $title = "<p><b>{$title}</b></p>"; } // Exclude some properties ($excludeProps) from $value. $value = array_diff_key($value, array_fill_keys($excludeProps, false)); if ($excludeEmpty) { $value = array_prune_empty($value); } return $value ? "{$title}<table class=__console-table><colgroup><col width=160><col width=100%></colgroup>\n" . implode('', map($value, function ($v, $k) use($depth, $maxDepth, $excludeProps, $excludeEmpty) { $v = self::grid($v, '', $maxDepth, $excludeProps, $excludeEmpty, $depth + 1); return "<tr><th>{$k}<td>{$v}"; })) . "\n</table>" : '<i>[]</i>'; }
/** * Builds a string with a list of the given items that are not empty (after begin trimmed), delimited by `$delimiter`. * * > <p>**Note:** an empty value is `null` or an empty string. * * @param string $delimiter * @param mixed ...$args * @return string */ function enum($delimiter) { $args = func_get_args(); array_shift($args); return join($delimiter, array_prune_empty(array_map('trim', $args))); }
/** * Returns the input array stripped of empty elements (those that are either `null` or empty strings). * * @return PowerArray Self, for chaining. */ function prune_empty() { $this->A = array_prune_empty($this->A); return $this; }