Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Loop trough object in PHP

I read trought How to loop through objects in php
But still don’t get it to work

Has someone an idea? Here is my php

$Topic_OBJ = json_decode($this->api_local_get($url));
$Text_IDS = "";
    
foreach ($Topic_OBJ as $obj) {
    $Text_IDS .= $obj->Text->Text_id.",";
}

$Topic_OBJ looks like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
        "TextContainer_id": 339131662,
        "Text": [
            {
                "Text_id": 794887707,
                "TextContainer_id": 339131662
            },
            {
                "Text_id": 794887711,
                "TextContainer_id": 339131662
            }
        ]
    }

But Text_IDS is only ",," but should be "794887707,794887711,"

Can someone help me please?
thanks rob

>Solution :

You should loop over the $Topic_OBJ->Text array instead like so…

<?php

$Topic_OBJ = json_decode($this->api_local_get($url));
$Text_IDS = "";
    
foreach ($Topic_OBJ->Text as $text) {
    $Text_IDS .= $text->Text_id.",";
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading