Skip to content

Instantly share code, notes, and snippets.

@lostsnow
Created May 9, 2013 09:58
Show Gist options
  • Save lostsnow/5546649 to your computer and use it in GitHub Desktop.
Save lostsnow/5546649 to your computer and use it in GitHub Desktop.
<?php
/**
* input:
* $arr = array(
* 'a' => array(
* 'b' => array(
* 'c' => 'bar'
* ),
* 'x' => 'i',
* )
* );
*
* output:
* a->b->c: bar
* a->x: i
*/
$arr = array(
'a' => array(
'b' => array(
'c' => 'bar=='
),
'x' => 'i',
)
);
echo array2objstr($arr);
function array2objstr($arr)
{
$str = http_build_query($arr);
$strs = explode('&', $str);
$objstr = '';
foreach ($strs as $s)
{
list($key, $value) = explode('=', $s);
$key = str_replace('][', '->', trim(urldecode($key), ']'));
$key = str_replace('[', '->', $key);
$objstr .= $key . ': ' . urldecode($value) . "\n";
}
return $objstr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment