我有这样的代码在我的symfony控制器:正确渲染数值数组,不是字符串数组
$em=$this->getDoctrine()->getManager();
$queryIndex = $em->createQuery('SELECT g.index
FROM MySpaceMyBundle:Graphique g');
$result = $queryIndex->getArrayResult();
$arrayResult = array_map('current', $result);
var_dump($arrayResult);
return $this->render('MySpaceMyBundle:MyFolder:myTemplate.html.twig');
用我的var_dump,我有这样的结果:
array (size=10)
0 => string '1700.000' (length=8)
1 => string '1200.000' (length=8)
2 => string '1200.000' (length=8)
3 => string '1304.000' (length=8)
4 => string '1800.000' (length=8)
5 => string '2012.000' (length=8)
6 => string '2048.000' (length=8)
7 => string '1048.000' (length=8)
8 => string '3000.000' (length=8)
9 => string '5421.000' (length=8)
但对于obHighchartBundle(使用highchart.js)我想要的结果是:
[1700,1200,1200,1304,1800,2012,2048,1048,3000,5421]
我该如何继续?
请注意,我需要传递一个数值数组(值是在我的数据库中的十进制类型),而不是数组与字符串。
表示最好的解决办法,即使TGA答案是好的。我有另一个问题给你:如果我的数组中的值是日期(日期时间)我怎么能在我的foreach循环这里'$ result [] =(int)$ value'?非常感谢你的回答。 –
@french_dev DateTime返回一个对象,我不认为你可以将它转换为int,而应该获取单个值(如年,月或日等等,就像这样'$ datetimeObj-> format(' d')')并使用它 – xurshid29
这就是我认为的日期时间。的确,datetime返回对象。谢谢你的回答,今天你是我的英雄。快乐的编码。 –