PHP 8.4.24 Released!

Voting

: six plus two?
(Example: nine)

The Note You're Voting On

me at peterkooi dot com
1 year ago
A small function for exporting variables as string, supporting nested arrays, with indented output, blockquoted and with double quotes, that can be pasted back in code.

<?php
function dump($value) {
  function _dump($value, $indent = 0) {
    if (!is_array($value)) return json_encode($value, JSON_NUMERIC_CHECK);
    foreach($value as $key => $item) $result .= (ifset($result) ? ",\r\n" . str_repeat(" ", $indent + 2) : "") . json_encode($key) . " => " . _dump($item, $indent + 2);
    return "[\r\n" . str_repeat(" ", $indent + 2) . "$result\r\n" . str_repeat(" ", $indent) . "]";
  }
  return "<pre>" . htmlspecialchars(_dump($value)) . "</pre>";
}

<< Back to user notes page

To Top