<?php
$products = json_decode('[
{ "title": "Product One", "categories": ["one", "two"] },
{ "title": "Product Two", "categories": ["two", "three"] },
{ "title": "Product Three", "categories": ["three", "four"] }
]');
$result = [];
foreach ($products as $row) {
if (in_array('two', $row->categories)) {
$result[] = $row;
}
}
echo json_encode($result, JSON_PRETTY_PRINT);
preferences:
29.84 ms | 406 KiB | 5 Q