我有一个mysql查询结果,我已经变成了一个数组:
$row = customfunction_fetch_array($results);
这是$row
数组的外观:
Array(
[0]=> Array ([Fruit]=> apple [Count]=>4 [Season]=>Summer
[1]=> Array ([Fruit]=> grape [Count]=>1 [Season]=>Fall
[2]=> Array ([Fruit]=> apple [Count]=>3 [Season]=>Winter
[3]=> Array ([Fruit]=> orange [Count]=>5 [Season]=>Spring
[4]=> Array ([Fruit]=> apple [Count]=>45 [Season]=>All
)
我要做的是循环显示特定字段的唯一值并将它们保存到新数组中。
$newArray =[];
foreach( $row["Fruit"] as $myFruits){
$newArray[] = $myFruits;
}
我收到警告:
“为foreach()提供的参数无效”
答案 0 :(得分:7)
根据您发布的数组,没有Highcharts.chart('container', {
chart: {
type: 'scatter'
},
plotOptions: {
series: {
lineWidth:1,
states: {
hover: {
lineWidthPlus: 2,
marker: {
enabled: true,
radius:3,
states: {
hover: {
fillColor:'#FF0000',
lineColor:'#00FF00',
lineWidth:3,
radius:12
}
}
}
}
},
marker: {
enabled: true,
radius:3,
states: {
hover: {
fillColor:'#FF0000',
lineColor:'#00FF00',
lineWidth:3,
radius:12
}
}
}
}
},
series: [{
data: [[29.9, 71.5], [106.4, 129.2], [144.0, 176.0], [135.6, 148.5], [216.4, 194.1], [95.6, 54.4]]
}]
});
,有$row['Fruit']
,$row[0]['Fruit']
等...
$row[1]['Fruit']
但是,要获得所有foreach($row as $values){
$newArray[] = $values['Fruit'];
}
,您只需执行此操作:
Fruits