function array_diff_assoc_recursive($array1, $array2) {
$difference=array();
foreach($array1 as $key => $value) {
if( is_array($value) ) {
if( !isset($array2[$key]) || !is_array($array2[$key]) ) {
$difference[$key] = $value;
} else {
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
if( !empty($new_diff) )
$difference[$key] = $new_diff;
}
} else if( !array_key_exists($key,$array2) || $array2[$key] !== $value ) {
$difference[$key] = $value;
}
}
return $difference;
}
$products = [
[
'product_id' => 102966,
'price' => 11,
],
[
'product_id' => 102967,
'price' => 22,
]
];
$attributes = [
[
'product_id' => 102966,
'attr_name' => 'Диагональ;Длительность ролика',
'attr_value' => '2";1 мин, 2 мин, 3 мин, 5 мин',
],
[
'product_id' => 102967,
'attr_name' => 'Выходы;Диагональ;Дополнительная информация',
'attr_value' => 'HDMI;2.7";рабочие диапазоны',
],
];
$products = array_map(function($product) use ( $attributes ) {
$attribute = array_filter($attributes, function($attribute) use ( $product ) {
return $attribute['product_id'] === $product['product_id'];
});
return array_merge($attribute ? current($attribute) : [], $product);
}, $products);
print_r($products);
function invalidRegex($regex)
{
if(preg_match($regex, null) !== false)
{
return '';
}
$errors = array(
PREG_NO_ERROR => 'Code 0 : No errors',
PREG_INTERNAL_ERROR => 'Code 1 : There was an internal PCRE error',
PREG_BACKTRACK_LIMIT_ERROR => 'Code 2 : Backtrack limit was exhausted',
PREG_RECURSION_LIMIT_ERROR => 'Code 3 : Recursion limit was exhausted',
PREG_BAD_UTF8_ERROR => 'Code 4 : The offset didn\'t correspond to the begin of a valid UTF-8 code point',
PREG_BAD_UTF8_OFFSET_ERROR => 'Code 5 : Malformed UTF-8 data',
);
return $errors[preg_last_error()];
}
function get_values_by_keys($input, $keys) {
return array_map(function($item) use ($input) {
return $input[$item];
}, $keys);
}
$json = '...';
$data = json_decode($json, true);
$comment = 77098646;
$results = array_filter($data['data'], function ($item) use ( $comment ) {
return $item['comment'] == $comment;
});
$status = $results ? 1 : 0;
$data = [
'64 654 руб.',
'231 654 руб.',
'9 879 руб.',
'164 руб.',
'2 815 руб.',
];
usort($data, function ($a, $b) {
return preg_replace('/[^0-9]/', '', $a) <=> preg_replace('/[^0-9]/', '', $b);
});
$min = current($data);