CodeIgniter Forums
When model returns an array of stdClass - how to iterate - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: When model returns an array of stdClass - how to iterate (/showthread.php?tid=87811)



When model returns an array of stdClass - how to iterate - Corsari - 06-02-2023

Hello

one kind hint

as you may know I'm not an experienced coder

I have a method in my model that returns an array of stdClass



[Image: array-of-class.jpg]



how should be iterated this ?

the classes are obviously rows of one table from the DB

Thank you for hints and tips


R.


RE: When model returns an array of stdClass - how to iterate - JustJohnQ - 06-02-2023

How do you generate this array?
Show us your code....


RE: When model returns an array of stdClass - how to iterate - sheilaf - 06-02-2023

PHP Code:
foreach ($data as $d) {
    // $d is object of stdClass
    // use arrow-notation to get to the stored values by their column names
    // $d->somecolumnname


HTH


RE: When model returns an array of stdClass - how to iterate - Corsari - 06-03-2023

(06-02-2023, 11:24 AM)sheilaf Wrote:
PHP Code:
foreach ($data as $d) {
    // $d is object of stdClass
    // use arrow-notation to get to the stored values by their column names
    // $d->somecolumnname


HTH
great!

thank you!!!! @sheilaf

I was finding only useless topics (or maybe I was wrongly formulating my searches on the web) where objects where instead associative arrays

So really Thank you, you took away a big headache from me Smile


Though for the sake of completeness

I'm experimenting with HTMX and I have made a live search which now works like a charm


RE: When model returns an array of stdClass - how to iterate - Corsari - 06-03-2023

And though , it works only disabling development environment

Looks like that XTMX conflicts with the CodeIgniter debug bar

I'll open a new thread about this