testing custom var_dump - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of testing custom var_dump.php
- <?php
- class FooBar
- {
- function foo_function()
- {
- return "Hello World!";
- }
- }
- $var_class = new FooBar;
- $example_array = [
- 'null' => null,
- 'null_text' => 'null',
- 'integer' => 10,
- 'integer_text' => '10',
- 'float' => 20.35,
- 'float_text' => '20.35',
- 'string' => 'Hello World',
- 'date_1' => '2021-01-17',
- 'date_2' => '2021-Jan-17',
- 'hour_1' => '6:31:00 AM',
- 'hour_2' => '17:31:00',
- 'datetime_1' => '2021-01-17 17:31:00',
- 'datetime_2' => '2021-Jan-17 6:31:00 AM',
- 'datetime_3' => '2021-01-17 6:31:00 AM',
- 'datetime_4' => '2021-Jan-17 17:31:00',
- 'currency_1' => '1.45$',
- 'currency_2' => '$ 1.45',
- 'array' => [
- 'boolean_true' => true,
- 'boolean_false' => false,
- 'boolean_true_text' => 'true',
- 'boolean_false_text' => 'false',
- ],
- 'objects_list' => [
- 'object' => (object) [],
- 'class' => $var_class,
- ],
- ];
- $example_array['array']['nested'] = ['other' => (object) ['apple', 'banana', 'coconut']];
- $pretty = function ($v = '', $c = " ", $in = -1, $k = null) use (&$pretty) {
- $r = '';
- if (in_array(gettype($v), array('object', 'array'))) {
- $r .= ($in != -1 ? str_repeat($c, $in) : '') . (is_null($k) ? '' : "$k: ") . '<br>';
- foreach ($v as $sk => $vl) {
- $r .= $pretty($vl, $c, $in + 1, $sk) . '<br>';
- }
- } else {
- $r .= ($in != -1 ? str_repeat($c, $in) : '') . (is_null($k) ? '' : "$k: ") . (is_null($v) ? '<NULL>' : "<strong>$v</strong>");
- }
- return $r;
- };
- echo $pretty($example_array);
File Description
- testing custom var_dump
- PHP Code
- 22 Feb-2021
- 1.67 Kb
You can Share it:
Latest PHP Pastes