我在找出如何在特定数组中搜索索引/匹配值时遇到了麻烦.
我可以列出并格式化所有内容,但我不确定发生了什么(它看起来不像数组中的数组,或者是吗?),也不知道如何在这种特定情况下搜索特定的索引/值.
示例:
{
"AppName": {
"date": "20230801",
"version": "6.8.48"
},
"Invoices": [
{
"Administration": {
"id": 2,
"code": "TEST",
"description": "Test Administration"
},
"Invoice": {
"id": 4350,
"type": "",
"invoiceNumber": 2340323,
"date": "2023-07-31T00:00:00.000Z",
"dueDate": "2023-08-14T00:00:00.000Z",
"amount": 196.3
},
"Relation": {
"nr": 102616,
"name": "John Doe"
},
"TermsOfPayment": {
"id": 11,
"description": "Prepayment"
}
},
{
"Administration": {
"id": 2,
"code": "TEST",
"description": "Test Administration"
},
"Invoice": {
"id": 4351,
"type": "",
"invoiceNumber": 2340324,
"date": "2023-07-31T00:00:00.000Z",
"dueDate": "2023-08-14T00:00:00.000Z",
"amount": 748.3
},
"Relation": {
"nr": 102158,
"name": "Jane Doe"
},
"TermsOfPayment": {
"id": 11,
"description": "Prepayment"
}
},
]
}
在列出我使用的值时:
$parsed = json_decode($received, true);
if ($parsed['AppName'] == true) {
$obj = json_decode($received);
$invoices = $obj->Invoices;
foreach ($invoices as $key => $value) {
$invoice_number = $value->Invoice->invoiceNumber;
$invoice_amount = $value->Invoice->amount;
print "<br>".$invoice_number;
print "<br>".$invoice_amount."<br>";
}
现在,下一步是搜索特定发票编号的金额.所以搜索2340324需要返回748.3
我try 使用ARRAY_SEARCH和ARRAY_COLUMN搜索/匹配关键字,但得到的结果都是空值.我一定是做错了什么,我猜这和"数组深度"有关?
任何关于如何处理这一问题的建议都将不胜感激.