How to loop through php object and replace string in each property (variable)
2 answers
You have to reference the $ value by reference and change it in place:
foreach($query_item as $key => &$value)
{
$value = str_replace(' & ',' & ',$value);
}
An alternative would be to reference an element within an object using the $ key:
foreach($query_item as $key => $value)
{
$query_item->$key = str_replace(' & ',' & ',$value);
}
I'll also specify htmlentities () , while we're going to replace and with amp ;.
+4
source to share