Debug_Bar_Pretty_Output::get_table PHP Method

get_table() public static method

Retrieve the table output.
Since: 1.3
public static get_table ( array $array, string $col1, string $col2, string | array $class = null ) : string
$array array Array to be shown in the table.
$col1 string Label for the first table column.
$col2 string Label for the second table column.
$class string | array One or more CSS classes to add to the table.
return string
        public static function get_table($array, $col1, $col2, $class = null)
        {
            $classes = 'debug-bar-table ' . sanitize_html_class(self::NAME);
            if (isset($class)) {
                if (is_string($class) && '' !== $class) {
                    $classes .= ' ' . sanitize_html_class($class);
                } else {
                    if (!empty($class) && is_array($class)) {
                        $class = array_map($class, 'sanitize_html_class');
                        $classes = $classes . ' ' . implode(' ', $class);
                    }
                }
            }
            $col1 = is_string($col1) ? $col1 : __('Key', 'db-pretty-output');
            $col2 = is_string($col2) ? $col2 : __('Value', 'db-pretty-output');
            $double_it = false;
            if (count($array) > self::TBODY_MAX) {
                $double_it = true;
            }
            $return = self::get_table_start($col1, $col2, $classes, $double_it);
            $return .= self::get_table_rows($array);
            $return .= self::get_table_end();
            return $return;
        }

Usage Example

 /**
  * Helper method to render the output in a table
  *
  * @param   array           $array  Array to be shown in the table
  * @param   string          $col1   Label for the first table column
  * @param   string          $col2   Label for the second table column
  * @param   string|array    $class  One or more CSS classes to add to the table
  */
 public function dbc_render_table($array, $col1 = null, $col2 = null, $class = null)
 {
     $classes = self::DBC_NAME;
     if (isset($class)) {
         if (is_string($class) && $class !== '') {
             $classes .= ' ' . $class;
         } else {
             if (is_array($class) && $class !== array()) {
                 $classes = $classes . ' ' . implode(' ', $class);
             }
         }
     }
     $col1 = isset($col1) ? $col1 : __('Name', self::DBC_NAME);
     $col2 = isset($col2) ? $col2 : __('Value', self::DBC_NAME);
     uksort($array, 'strnatcasecmp');
     if (defined('Debug_Bar_Pretty_Output::VERSION')) {
         echo Debug_Bar_Pretty_Output::get_table($array, $col1, $col2, $classes);
         // xss: ok
     } else {
         // An old version of the pretty output class was loaded
         Debug_Bar_Pretty_Output::render_table($array, $col1, $col2, $classes);
     }
 }
All Usage Examples Of Debug_Bar_Pretty_Output::get_table