我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

从一组对象中获取某种类型的元素

I have a array of objects like this one:

Array
(
    [0] => stdClass Object
        (
            [art_id] => 76
            [title] => whatever
        )

    [1] => stdClass Object
        (
            [art_id] => 216
            [title] => blabla
        )

)

Can I somehow get a array with all art_id's from it, without having to iterate it?

(like array(76, 216))

function getArtId($obj)
{
    return $obj->art_id;
}

$b = array_map("getArtId", $a);
print_r($b);

This is indirectly an iteration, but you do not need to write code for the loop yourself.

近期文章

  • 请问这个芯片是什么型号
  • python 龟图学习
  • Cannot set properties of null (setting 'value')
  • K-means能不能保存模型?
  • formRef.value.validateFields is not a function
  • 与paypal IPN交易后发送电子邮件
  • xlinix FPGA V7中CPLL使用相邻quad参考时钟接入SOUTHREFCLK时,CPLL无法锁定
  • 接收RS485报文数据显示乱码
  • 'error': 'Bad Request', 'message': "JSON parse error: Unrecognized token 'channel'
  • 左边将1个表连接到MYSQL中的多个表
  • C语言不知道怎么进行下去了
  • MYSQL在合并显示结果时遇到的问题
  • STM32H750XBH6 外部中断 HAL库
  • 请问使用那个工具软件制作安装程序?
  • 怎么自己给自己颁发SSL证书
  • qt sqlite数据库打包
  • MeteoInfo计算轨迹
  • 用西门子软件,编辑梯形图
  • 通过php / android在排序的mySQL表中的正确位置插入数据
  • 关于#c++#的问题,请各位专家解答!

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华