Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implode all the properties of a given name in an array of object - PHP [duplicate]

Is there a way to implode the values of similar objects contained in an array? I have an array of objects:

$this->inObjs

and I'd like a comma separated string of each of their messageID properties:

$this->inObjs[$i]->messageID

Is there an elegant way to do this or am I going to have to MacGyver a solution with get_object_vars or foreachs or something similar? Thanks for the help.

like image 476
linus72982 Avatar asked Dec 21 '22 15:12

linus72982


1 Answers

$allMessageID = '';
foreach ($this->inObjs as $objectDetail) :
    $allMessageID[] = $objectDetail->messageID;
endforeach;

$allMessageID_implode = implode(",", $allMessageID);

echo $allMessageID_implode;
like image 90
naveenos Avatar answered May 11 '23 00:05

naveenos