Created
May 9, 2013 09:58
-
-
Save lostsnow/5546649 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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