<?php
header('Content-type: text/plain');
$metaarr = array(
array(
"post_id" => '34',
"meta_key" => "product_shops_0_price",
"meta_value"=> "25"
),
array(
"post_id" => '34',
"meta_key" => "product_shops_0_price_old",
"meta_value"=> "45"
),
array(
"post_id" => '34',
"meta_key" => "product_shops_1_price",
"meta_value"=> "25"
),
array(
"post_id" => '34',
"meta_key" => "product_shops_1_price_old",
"meta_value"=> "45"
)
);
$map = array();
foreach ($metaarr as $key => $value) {
$splarr = preg_match('/^(product_shops_\d*)_(\S*)/', $value['meta_key'], $matches);
$product_offset = $matches[1];
$map[$value['post_id']][$product_offset][$value['meta_key']] = $value['meta_value'];
}
print_r($map);
- Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.5 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- Array
(
[34] => Array
(
[product_shops_0] => Array
(
[product_shops_0_price] => 25
[product_shops_0_price_old] => 45
)
[product_shops_1] => Array
(
[product_shops_1_price] => 25
[product_shops_1_price_old] => 45
)
)
)
preferences:
114.03 ms | 404 KiB | 170 Q