Created
May 22, 2012 21:46
-
-
Save prufrock/2771834 to your computer and use it in GitHub Desktop.
Makes XML and JSON play nice when being rendered from the same associate array.
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 | |
function removeSingularKeys($array, $parent="") | |
{ | |
$result = array(); | |
$result = $array; | |
foreach($array as $key => $value){ | |
if(keyIsTheSingularFormOf($key, $parent)){ | |
return $value; | |
} | |
if(is_array($value)){ | |
$result[$key] = removeSingularKeys($value, $key); | |
} | |
} | |
return $result; | |
} | |
function keyIsTheSingularFormOf($key, $parent){ | |
if($parent == $key . "s"){ | |
return TRUE; | |
} | |
return FALSE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment