Я получаю json. А вывести мне его надо в цикле на странице со сложной html структурой. Т.е. только шаблонизатор? )Во первых, судя по тому что используется jq, никаких "шаблонизаторов"/движков у вас не подключено (не факт, но скорее всего).
DATE_FORMAT(CURRENT_DATE - INTERVAL 11 MONTH, '%Y-%m-01' AND `category_id` = '1')
AND `category_id` = '2' AND `category_id` = '3'
SELECT
SUM(`price`) as `sales`,
SUM(`seller_salary`) as `salary`,
COUNT(CASE WHEN `category_id` = '1' THEN 1 END) as cat1_count,
COUNT(CASE WHEN `category_id` = '2' OR `category_id` = '3' THEN 1 END) as cat23_count,
DATE_FORMAT(`putdate`, '%Y-%m') as period
FROM `ms_sales`
WHERE `putdate` >= DATE_FORMAT(CURRENT_DATE - INTERVAL 11 MONTH, '%Y-%m-01')
GROUP BY period
/**
* Prepare array for our job
*/
$arrayOne = [
0 => 80,
1 => 80,
2 => 90,
];
$arrayTwo = [
0 => [
0 => 190,
1 => 195,
],
1 => [
0 => 200,
],
2 => [
0 => 190,
1 => 195,
],
];
$arrayThree = [
0 => 1,
1 => 2,
2 => 3,
];
/**
* @var array Array with actual data in our structure
*/
$arResult = [];
foreach ( $arrayTwo as $iKeyOne => $arrayTwoElement )
{
// if in second array exist unknown key
if ( !array_key_exists($iKeyOne, $arrayOne) )
{
continue;
}
// if in third array exist unknown key
if ( !array_key_exists($iKeyOne, $arrayThree) )
{
continue;
}
// if in second array no elements
if ( empty($arrayTwoElement) || !is_array($arrayTwoElement) )
{
continue;
}
/* @var integer Key for first depth level */
$iLevelKey = (int) $arrayOne[ $iKeyOne ];
/* @var integer Value for second depth level */
$iLevelValue = (int) $arrayThree[ $iKeyOne ];
foreach ($arrayTwoElement as $k => $v)
{
$arResult[ $iLevelKey ][ $v ] = $iLevelValue;
}
}
var_dump($arResult);
/*
Will display:
array(2) {
[80]=>
array(3) {
[190]=> int(1)
[195]=> int(1)
[200]=> int(2)
}
[90]=>
array(2) {
[190]=> int(3)
[195]=> int(3)
}
}
*/