/** * Tests correct display of multilevel associative arrays. * * @return void */ public function testNonAssociativeArray() { $this->assertEquals( "key[0]: \"value0\"\nkey[1]: \"value1\"\n", PMA_prettyPrint(array('key' => array('value0', 'value1'))) ); }
/** * pretty print a variable for the user * * @param mixed $object the variable to pretty print * @param String $namespace the namespace to use for printing values * * @return String the human readable form of the variable */ function PMA_prettyPrint($object, $namespace = "") { if (!is_array($object)) { if (empty($namespace)) { return "{$object}\n"; } else { return "{$namespace}: \"{$object}\"\n"; } } $output = ""; foreach ($object as $key => $value) { if ($namespace == "") { $new_namespace = "{$key}"; } else { $new_namespace = $namespace . "[{$key}]"; } $output .= PMA_prettyPrint($value, $new_namespace); } return $output; }