如何摆脱以下数组中的数字索引:
[0] => Array
(
[0] => Array
(
[ 2018:08:30-07:00:00 ] => 16.772925
)
[1] => Array
(
[ 2018:08:30-07:15:00 ] => 16.770355
)
[2] => Array
(
[ 2018:08:30-07:30:00 ] => 16.77907
)
[3] => Array
(
[ 2018:08:30-07:45:00 ] => 16.78735
)
)
[1] => Array
(
[0] => Array
(
[ 2018:08:30-07:00:00 ] => 16.772925
)
)
看起来像这样:
[0] => Array
(
[ 2018:08:30-07:00:00 ] => 16.772925
[ 2018:08:30-07:15:00 ] => 16.770355
[ 2018:08:30-07:30:00 ] => 16.77907
[ 2018:08:30-07:45:00 ] => 16.78735
)
[1] => Array
(
[ 2018:08:30-07:00:00 ] => 16.772925
)
我的php代码:
$time_to_priceee_1 = array();
$z_1 = 0;
foreach($pvt_1 as $pvtt_1)
{
echo '1';
$y_1 = 0;
foreach($pvtt_1 as $pvttt_1 => $pvtttt_1)
{
$time_to_price_1[$z_1][$y_1] = $pvtttt_1['time'];
$time_to_pricee_1[$z_1][$y_1] = $pvtttt_1['price'];
$time_to_priceee_1[$z_1][$y_1] = array($pvtttt_1['time'] => $pvtttt_1['price']);
$y_1 = $y_1 + 1;
}
$z_1 = $z_1 + 1;
}
$time_to_priceee_1
的输出是我发布的第一个数组。那就是我似乎得到的。尝试过$time_to_priceee_1[$z_1]
,$time_to_priceee_1
,$time_to_priceee_1[]
,$time_to_priceee_1[$z_1][$y_1] = array($pvtttt_1['time'], $pvtttt_1['price'])
,但我认为我尝试的区域错误。
谢谢。
答案 0 :(得分:0)
对不起,已经解决了。这是有效的代码:
$time_to_priceee_1[$z_1][$pvtttt_1['time']] = $pvtttt_1['price'];
\
还是谢谢。