需要帮助访问像PHP对象

时间:2018-06-26 15:07:52

标签: php

我有这个 Primary Dataframe | Name | Date | A | A Prime | B | Proto Name | |--------|-----------|------|---------|---------|------------| | Z3Pats | 6/1/2018 | 3.24 | 3.24 | 0.16575 | Alpha | | Z3Pats | 5/1/2018 | 3.23 | NaN | NaN | Alpha | | Z3Pats | 4/1/2018 | 3.21 | NaN | NaN | Alpha | | Z3Pats | 3/1/2018 | 3.20 | 3.20 | 0.16506 | Alpha | | Z3Pats | 2/1/2018 | 3.16 | 3.16 | 0.16434 | Alpha | | CO-119 | 5/1/2018 | 1.53 | NaN | NaN | Bravo | | CO-119 | 4/1/2018 | 1.51 | NaN | NaN | Bravo | | CO-119 | 3/1/2018 | 1.48 | 1.48 | 0.10614 | Bravo | | CO-119 | 2/1/2018 | 1.48 | 1.48 | 0.10614 | Bravo | | CO-119 | 1/1/2018 | 1.45 | NaN | NaN | Bravo | | CO-119 | 12/1/2017 | 1.44 | 1.44 | 0.10469 | Bravo | | CO-119 | 11/1/2017 | 1.41 | 1.41 | 0.10396 | Bravo |

array

我的意图是将数组作为对象访问,例如:$data = array( 'employer' => $employer, 'manager' => $manager );

我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以像这样将数组类型转换为对象:

<?php

$data = array(
    'employer' => "employer",
    'manager' => "manager "
);

$object = (object) $data;

var_dump($object->employer); // => "employer"

返回的值将是\stdClassas described in the documentation的实例。