Skip to content

Instantly share code, notes, and snippets.

@lenasterg
Created May 30, 2018 09:55
Show Gist options
  • Select an option

  • Save lenasterg/a7102bfba78bb3d166ac3c6dce543c49 to your computer and use it in GitHub Desktop.

Select an option

Save lenasterg/a7102bfba78bb3d166ac3c6dce543c49 to your computer and use it in GitHub Desktop.
PHP JSON - Remove unwanted keys from json
/**
* 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