<?php
$categories = '
[
{
"id":5,
"parent_id":0,
"image_url":"https://files.cdn.printful.com/o/upload/catalog_category/77/7776d01e716d80e3ffbdebbf3db6b198_t?v=1652883254",
"title":"Home & living"
},
{
"id":6,
"parent_id":1,
"image_url":"https://files.cdn.printful.com/o/upload/catalog_category/4b/4b37924aaa8e264d1d3cd2a54beb6436_t?v=1652883254",
"title":"All shirts"
}
]
';
$data = json_decode($categories, true);
$relevant = array_filter($data, function($entry) {
return $entry['parent_id'] !== 0;
});
var_dump($relevant);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- array(1) {
[1]=>
array(4) {
["id"]=>
int(6)
["parent_id"]=>
int(1)
["image_url"]=>
string(107) "https://files.cdn.printful.com/o/upload/catalog_category/4b/4b37924aaa8e264d1d3cd2a54beb6436_t?v=1652883254"
["title"]=>
string(10) "All shirts"
}
}
preferences:
125.26 ms | 403 KiB | 123 Q