Skip to content

Instantly share code, notes, and snippets.

@gquemener
Created August 29, 2013 14:14
Show Gist options
  • Save gquemener/6378634 to your computer and use it in GitHub Desktop.
Save gquemener/6378634 to your computer and use it in GitHub Desktop.
<?php
function formatAsString($data)
{
if (is_array($data)) {
$result = array();
foreach ($data as $key => $value) {
$result[] = sprintf('%s => %s', formatAsString($key), formatAsString($value));
}
return sprintf("[%s]", join(', ', $result));
}
if (is_bool($data)) {
return $data ? 'true' : 'false';
}
return (string) $data;
}
var_dump(formatAsString('foo'));
var_dump(formatAsString(true));
var_dump(formatAsString(array(array('foo' => 'a', 'c', 'd' => false), 'b')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment