gpt4 book ai didi

php - 遍历具有私有(private)属性的对象

转载 作者:可可西里 更新时间:2023-10-31 23:07:37 25 4
gpt4 key购买 nike

我将 PHP 与 php 事件记录一起使用。当我从数据库中检索记录时,属性被列为私有(private)。我需要遍历属性并检索键 => 值对。如何才能做到这一点?

$row = \Models\Locations::find(2);

Models\Locations Object
(
[errors] =>
[attributes:ActiveRecord\Model:private] => Array
(
[id] => 2
[customer_id] => 6
[name] => test location
[address_line1] => 123 test Drive
[address_line2] =>
[city] => Moon Township
[state] => AZ
[zip] => 12345
[country] => USA
[primary_phone_number] => 123.456.7890
[latitude] => 0
[longitude] => 0
[coordinate_precision] =>
)

[__dirty:ActiveRecord\Model:private] => Array
(
)

[__readonly:ActiveRecord\Model:private] =>
[__relationships:ActiveRecord\Model:private] => Array
(
)

[__new_record:ActiveRecord\Model:private] =>
)

最佳答案

只需使用模型的方法attributes :$row->attributes()

关于php - 遍历具有私有(private)属性的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13126759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com