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);
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Deprecated: Automatic conversion of false to array is deprecated in /in/e44aG on line 14 Array ( [0] => Array ( [temp] => 1 ) ) Deprecated: Automatic conversion of false to array is deprecated in /in/e44aG on line 23 Array ( [0] => Array ( [temp1] => 2 ) [1] => Array ( [temp3] => 2 ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Array ( [0] => Array ( [temp] => 1 ) ) Array ( [0] => Array ( [temp1] => 2 ) [1] => Array ( [temp3] => 2 ) )

preferences:
145.15 ms | 410 KiB | 5 Q