To wrap all the object values which match the word 'test' in a span, you will need to iterate through the object properties as well as the array itself. You can do this using foreach:
foreach ($object in $array) {
foreach ($property in $object) {
if ($object->$property == 'test') {
$object->$property = "<span>{$object->property}</span>";
}
}
}
If you want to wrap all instances of the word test within property values with a span, you can do it using preg_replace as follows:
foreach ($object in $array) {
foreach ($property in $object) {
$object->$property = preg_replace('/\b(test)\b/', '<span>$1</span>', $object->$property);
}
}
Given the string "This test is for testing purposes as a test", the above call will spit out this:
This <span>test</span> is for testing purposes as a <span>test</span>.