note 129839 added to function.var-export

From: Date: Wed, 06 Nov 2024 14:02:12 +0000
Subject: note 129839 added to function.var-export
Groups: php.notes 
Request: Send a blank email to php-notes+get-221634@lists.php.net to get a copy of this message
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>"; } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 82.172.36.179) ---- Manual Page -- https://php.net/manual/en/function.var-export.php Edit -- https://main.php.net/note/edit/129839 Del: integrated -- https://main.php.net/note/delete/129839/integrated Del: useless -- https://main.php.net/note/delete/129839/useless Del: bad code -- https://main.php.net/note/delete/129839/bad+code Del: spam -- https://main.php.net/note/delete/129839/spam Del: non-english -- https://main.php.net/note/delete/129839/non-english Del: in docs -- https://main.php.net/note/delete/129839/in+docs Del: other reasons-- https://main.php.net/note/delete/129839 Reject -- https://main.php.net/note/reject/129839 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221634) next »