php - 在嵌套数组 php 转储中显示第二个数组的结果
问题描述
我有以下代码:
public function canceledReasons()
{
$searchs = Zendesk::search()->find('type:ticket tags:cancel');
$searchs = json_decode(json_encode($searchs),true);
foreach ($searchs as $search) {
dump($search);
}
}
它返回一个数组,其中包含一些嵌套数组我试图在“标签”中显示第二个数组(如果存在)。那里可能有多个数组,因此最好将它们全部显示出来。
Results
array:100 [▼
0 => array:36 [▼
"url" => "https://example/api/v2/tickets/example.json"
"id" => example
"external_id" => null
"via" => array:2 [ …2]
"created_at" => "2019-08-28T02:05:22Z"
"updated_at" => "2019-08-29T23:00:54Z"
"type" => null
"subject" => "example"
"raw_subject" => "example"
"description" => """
From: example\n
Phone: \n
Location: example\n
URL: https://example.zendesk.com/hc/en-us/categories/#####-Account-Billing\n
Department: \n
\n
Hi,\n
please cancel ▶
\n
Best,\n
Vinay\n
\n
----\n
Zopim\n
https://www.example.com
"""
"priority" => null
"status" => "open"
"recipient" => "example"
"requester_id" => example
"submitter_id" => example
"assignee_id" => example
"organization_id" => null
"group_id" => example
"collaborator_ids" => []
"follower_ids" => []
"email_cc_ids" => []
"forum_topic_id" => null
"problem_id" => null
"has_incidents" => false
"is_public" => true
"due_at" => null
"tags" => array:2 [ …2]
"custom_fields" => array:2 [ …2]
"satisfaction_rating" => null
"sharing_agreement_ids" => []
"fields" => array:2 [ …2]
"followup_ids" => []
"brand_id" => example
"allow_channelback" => false
"allow_attachments" => true
"result_type" => "ticket"
]
1 => array:36 [▶]
2 => array:36 [▶]
3 => array:36 [▶]
4 => array:36 [▶]
当我尝试
dump($search['tags']);
它返回未定义的索引:标签
只是试图获得“标签”数组的结果。
谢谢您的帮助。
解决方案
尝试这个...
public function canceledReasons()
{
$searchs = Zendesk::search()->find('type:ticket tags:cancel');
$searchs = json_decode(json_encode($searchs),true);
foreach ($searchs as $search) {
dump($search[0]['tags']);
//or to get all tags array value
foreach ($search[0]['tags'] as $tag) {
dump($tag);
}
}
}
```
推荐阅读
- android - 仍然使用同步列表获得并发修改异常
- visual-studio-code - 为什么 Visual Studio 代码和大多数应用程序没有安装在新的 Windows 10 中?
- nginx - nginx反向到所有页面
- selenium - url 导航中的问题:Selenium 和 ChromeDriver
- amazon-web-services - 隐藏 S3 下载源
- excel - 以只读方式打开 Excel,但避免显示消息栏
- java - com.sun.xml.internal.ws.fault.ServerSOAPFaultException
- java - 使用 j2mod 的 Modbus 从站的非法地址问题
- c# - 在 c# 中将 linq 与包含嵌套 IEnumerable 的对象一起使用
- microsoft-graph-api - 微软团队订阅