在对象数组中放大给定名称的所有属性-PHP [英] Implode all the properties of a given name in an array of object - PHP

查看:67
本文介绍了在对象数组中放大给定名称的所有属性-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法内含数组中相似对象的值?我有一个对象数组:

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

$this->inObjs

,我想用逗号分隔的每个 messageID 属性的字符串:

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

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

是否有一种优雅的方法可以做到这一点,或者我是否必须使用 MacGyver 解决方案get_object_vars foreachs 或类似的东西?

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.

推荐答案

$messageIDArray;
foreach($this->inObjs as $obj){
   $messageIDArray[] = $obj->messageID;
}

$string = implode(',',$messageIDArray);

这篇关于在对象数组中放大给定名称的所有属性-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆