Created
May 30, 2018 09:55
-
-
Save lenasterg/a7102bfba78bb3d166ac3c6dce543c49 to your computer and use it in GitHub Desktop.
PHP JSON - Remove unwanted keys from json
This file contains hidden or 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
| /** | |
| * Removes unwanted keys from JSON string | |
| * @param string $response | |
| * @param array $exclude | |
| * @return string | |
| * | |
| * | |
| */ | |
| function ls_remove_unwanted_from_json($response , $exclude) { | |
| $jsonArray = json_decode($response , true); | |
| foreach ( $jsonArray as $key => $value ) { | |
| foreach ( $exclude as $keyToRemove ) { | |
| unset($jsonArray[$key][$keyToRemove]); | |
| } | |
| } | |
| return json_encode($jsonArray); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment