我对php处理数组的方式并不熟悉,在 .NET 中我可以使用这种方法访问数组
array[x][y];
我的问题是:
我正在从数据库中检索记录并将其返回到$res_merchant_field
$res_merchant_field = $this->CI->merchantfield_model->merchantfield_list( $str_where );
和$res_merchant_field
将填充此记录:
Array
(
[0] => stdClass Object
(
[MFID] => 1
[MFName] => Bill No
[FTID] => 1
[DTID] => 1
[MFRequired] => 1
[MFDefaultValue] =>
[MFDueDate] => 0
[MFToBePaid] => 0
[MFMaxLength] => 12
[MFOrderNo] => 1
[MFStatus] => 1
)
[1] => stdClass Object
(
[MFID] => 2
[MFName] => Gallons Consumed
[FTID] => 1
[DTID] => 2
[MFRequired] => 1
[MFDefaultValue] =>
[MFDueDate] => 0
[MFToBePaid] => 0
[MFMaxLength] => 5
[MFOrderNo] => 2
[MFStatus] => 1
)
[2] => stdClass Object
(
[MFID] => 3
[MFName] => Amount Due
[FTID] => 3
[DTID] => 1
[MFRequired] => 1
[MFDefaultValue] =>
[MFDueDate] => 0
[MFToBePaid] => 1
[MFMaxLength] => 15
[MFOrderNo] => 3
[MFStatus] => 1
)
)
如何在以下条件下访问和获取该数组的记录:
示例:
获得MFID = 1,DTID将为1,如果我得到MFID = 3,则DTID将为1.
或如何访问数组$array[x][y]
?
提前致谢。
答案 0 :(得分:1)
问题是第二级不是数组而是对象,要访问属性,您必须使用此格式。
$array[$x]->$y;
不幸的是,您无法通过索引访问属性获取您需要说出的第0个项目的MFID
$array[0]->MFID;