remove_property
TABLE OF CONTENTS
Remove one or more properties from an object
Definition
object remove_property(object $object, string|array[string] $key)
Returns an object with all the properties of $object except $key. If $key doesn’t exist in $object, returns $object as is.
Parameters
object $object
Object inside which to remove the property.
string|array[string] $key
Key(s) of properties inside $object to remove. Can be a single string or an array of strings.
Returns
object
Returns $object without the properties in $key.
Examples
Sample data
{
"person": {
"firstName": "Jane",
"lastName": "Doe",
"age": 30,
"status": {
"Enabled": true
},
"roles": [
"User",
"Admin"
]
}
}Transformation
{
objectWithoutAge: remove_property(person, 'age'),
objectWithoutName: remove_property(person, ['firstName','lastName'])
}Result
{
"objectWithoutAge": {
"firstName": "Jane",
"lastName": "Doe",
"status": {
"Enabled": true
},
"roles": [
"User",
"Admin"
]
},
"objectWithoutName": {
"age": 30,
"status": {
"Enabled": true
},
"roles": [
"User",
"Admin"
]
}
}Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article