简体   繁体   中英

Is it possible to get all the nodes with a specific name from a PHP array?

I am converting to a PHP array from a Facebook API response in JSON format. The result is a multilevel array with many elements named id on every level.

I would like to retrieve all the elements with the name id and I was wondering if there is any direct way to get all those elements without having to parse each level of the array to grab the element.

Hope this question makes sense, Any tip will be much appreciated.

使用数组列功能

$output = array_column($input, 'id');

如果您没有php 5.5(即没有array_column ),则可以使用以下命令:

$ids = array_map(function($element) {return $element['id'];}, $input);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM