#PHP_LOOP

5 messages · Page 1 of 1 (latest)

serene moth
#

how can i loop through the array $array=[{"projectId":180,"projectName":"IRP-5"},{"projectId":122,"projectName":"Spectra"}]

cunning snow
#

That isn't a proper php array, it looks like a json string.

serene moth
#

i am getting this from api

cunning snow
#

Then you'll need to decode it, kind of like this -

#
$myJsonArrayString = '[{"projectId":180,"projectName":"IRP-5"},{"projectId":122,"projectName":"Spectra"}]';

$array = json_decode($myJsonArrayString);

foreach ($array as $item) {
    print $item->projectName;
}