PHP   发布时间:2022-04-05  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-根据条件从数组嵌套返回元素大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我试在数组中搜索元素(在本例中为“电子”),然后返回嵌套值.

我正在使用的阵列

array:2 [▼
  0 => array:2 [▼
    "value" => "0241-6230"
    "type" => "print"
  ]
  1 => array:2 [▼
    "value" => "2339-1623"
    "type" => "electronic"
  ]
]

下面是我正在使用的代码.

<?PHP

$this->doi = 'anydoinumber';
$this->client = new Client();
$this->Url = 'https://api.crossref.org/works/:'.$this->doi;
$res = $this->client->get($this->Url);
$decoded_items = json_decode($res->getBody(), truE);

if (isset($decoded_items['message']['issn-type'])) {
    $this->issn = '';
} else {
    // no electronic issn given
    Log.Alert('No electronic issn for :'.$this->Doi);
}

我期望的输出

$this->issn = "2339-1623"

解决方法:

您可以使用laravel集合:

collect($array)->where('type', 'electronic')->first();

输出为:

array:2 [
  "value" => "2339-1623"
  "type" => "electronic"
]

大佬总结

以上是大佬教程为你收集整理的php-根据条件从数组嵌套返回元素全部内容,希望文章能够帮你解决php-根据条件从数组嵌套返回元素所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: