I have data selected from database in object format. I want to loop it but I also include text randomly to the display. How to add that text to a random place in object? or how to print it randomly once inside the loop?
//Object data
$obj = (object) [
'0' => ['name' => 'Banana'], '1' => ['name' => 'Potato'], '2' => ['name' => 'Mango']
];
//addition text will be displayed
$text = 'My random text';
foreach($obj as $d) {
echo $d->name;
}
Result can be
Banana
Potato
My random text
Mango
Or
My random text
Banana
Potato
Mango
Or
Banana
My random text
Potato
Mango
...