3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ "a:1:{i:0;i:1;}", "a:3:{i:0;i:2;i:1;i:2;i:2;i:3;}", "a:3:{i:0;i:3;i:1;i:2;i:2;i:3;}", ]; $row = [['temp' => 1], ['temp1' => 2], ['temp3' => 2]]; $temp = array_map('unserialize', $arr); $brand_id = 1; $result = false; foreach ($temp as $key => $value) { if (!empty($value) && in_array($brand_id, $value)) { $result[] = $row[$key]; } } print_r($result); $brand_id = 2; $result = false; foreach ($temp as $key => $value) { if (!empty($value) && in_array($brand_id, $value)) { $result[] = $row[$key]; } } print_r($result);

preferences:
27.39 ms | 407 KiB | 5 Q