-1

I did a query in php and all the results are stored in an object. For example

$query = "select * from some_table";
$sth = $dbc->query($query);
$results = $sth->fetchAll();

Therefore the results of the query is stored in $results and I have a property called name. How can I now loop through this object $results to change all the values of a certain property name of the object.

jszobody
  • 28,495
  • 6
  • 61
  • 72
Kern Elliott
  • 1,659
  • 5
  • 41
  • 65

1 Answers1

1

Assuming name is a public property:

for($i = 0; $i < count($results); $i++){
  $results[$i]->name = ...; 
}
Headshota
  • 21,021
  • 11
  • 61
  • 82