将对象数组转换为纯数组并访问它们

时间:2018-06-18 06:54:26

标签: php arrays object

我有一系列对象:

array(1) {
[0]=>
object(Local\Model\PaymentModel)#259 (2) {
["_id":protected]=>
string(1) "1"
["_data":protected]=>
array(4) {
  ["payment_supplier"]=>
  string(15) "ACCESS MOBILITY"
  ["payment_ref"]=>
  string(6) "499778"
  ["payment_cost_rating"]=>
  string(1) "3"
  ["payment_amount"]=>
  string(7) "3694.60"
}
}

我试图转换它:

foreach($data['payments'] as $payment) {
  $array[] = (array) $payment;
}

结果我变得像这样:

array(2) {
["*_id"]=>
string(1) "1"
["*_data"]=>
array(4) {
  ["payment_supplier"]=>
  string(15) "ACCESS MOBILITY"
  ["payment_ref"]=>
  string(6) "499778"
  ["payment_cost_rating"]=>
  string(1) "3"
  ["payment_amount"]=>
  string(7) "3694.60"
}
}

我试过了:

var_dump(array[0]['*_id']);

但我在第57行的C:\ xampp \ htdocs \ tsh \ v1 \ index.php中收到错误'未定义索引:* _id'

我的问题是:如何访问这些数据?

0 个答案:

没有答案