我使用PHP和PHP活動記錄。當我從數據庫中檢索記錄時,這些屬性被列爲私有。我需要迭代屬性並檢索key => value對。如何才能做到這一點?使用私有屬性對對象進行迭代
$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] =>
)
就像一個快速測試,我嘗試$行 - >屬性(),它的工作!我現在可以迭代返回。謝謝!! – kdm