0
i obtain by means of a query to the database the results in stdClass. So far so good, but I will have to add a new property in the result. Someone could help me do that, I’ve been doing some research but I didn’t have one.
Like this:
array (
0 =>
object(stdClass)
public 'aaaaaaa' => string '3'
public 'aaaaaaaa' => string 'bbbbb'
1 =>
object(stdClass)
public 'aaaaaaa' => string '4'
public 'aaaaaaaa' => string 'ccccccc'
What I want:
array (
0 =>
object(stdClass)[66]
public 'aaaaaaa' => string '3'
public 'aaaaaaaa' => string 'bbbbb'
public 'nova' => string 'yyyy'
1 =>
object(stdClass)[66]
public 'aaaaaaa' => string '4'
public 'aaaaaaaa' => string 'ccccccc'
public 'nova' => string 'cccc'
I’m trying through the foreach:
foreach ($variavel as $key => $value) {
}
It wouldn’t just be
$value->nova = 'yyyy'
?– Woss
@Andersoncarloswoss guy was breaking his head and I didn’t even remember to take it for the value. That’s right, you saved me. Thank you. As I put as the correct answer this your comment?
– AntonioSantos
Assigning a key and a value to an object
– NoobSaibot