我需要基于 php 数组创建图表,我在 stackoverflow 帖子中发现了一些关于遍历的内容,但这些答案对转换它没有帮助:
Array
(
[product sample 1] => Array
(
[0] => Array
(
[hitsTotal] => 63
)
[1] => Array
(
[hitsTotal] => 113
)
)
[product sample 2] => Array
(
[0] => Array
(
[hitsTotal] => 57
)
[1] => Array
(
[hitsTotal] => 107
)
)
)
到
['product sample 1', 63, 113],
['product sample 2', 57, 107]
如何转换?
最佳答案
假设 $input
是您在帖子中显示的数组,您可以执行以下操作:
$output = array();
foreach($input as $key => $value)
{
$obj = array();
$obj[] = $key;
$obj[] = $value[0]['hitsTotal'];
$obj[] = $value[1]['hitsTotal'];
$output[] = $obj;
}
var_dump($output); //This will print it on screen so you can validate the output
关于javascript - 彼此相邻的 PHP 数组键值以在 javascript 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37367519/