我尝试每次在foreach()中返回数据,但我一直在循环的第一次迭代中获取数据,以下是我的代码
for ($i = 0 ;$i<4;$i++)
{
var_dump($i);
$publisher = Publisher::find($results[$i]->publisherId);
//pr($publisher);
$channels =$publisher->channels()->get() ;
pr($channels[0]);
$data = ReviveAgent::getPublisherDailyStatistics($channels[0],$start,$end);
pr($data);
return Response::json($data);
}
在var_dump($i)上;它只显示前0的数据。那么如何返回1、2、3的数据呢
以下是var_dump($i)pr($data)= 1时的输出
array (
0 =>
array (
'impressions' => 1867,
'clicks' => 14,
'requests' => 44,
'revenue' => 2.79,
'day' =>
stdClass::__set_state(array(
'scalar' => '20150518T00:00:00',
'timestamp' => 1431907200,
'xmlrpc_type' => 'datetime',
)),
),
1 =>
array (
'impressions' => 2197,
'clicks' => 17,
'requests' => 382,
'revenue' => 19.829999999999998,
'day' =>
stdClass::__set_state(array(
'scalar' => '20150519T00:00:00',
'timestamp' => 1431993600,
'xmlrpc_type' => 'datetime',
)),
),
2 =>
array (
'impressions' => 5484,
'clicks' => 3,
'requests' => 3680,
'revenue' => 6.7300000000000004,
'day' =>
stdClass::__set_state(array(
'scalar' => '20150520T00:00:00',
'timestamp' => 1432080000,
'xmlrpc_type' => 'datetime',
)),
),
3 =>
array (
'impressions' => 6909,
'clicks' => 105,
'requests' => 5141,
'revenue' => 378.88499999999999,
'day' =>
stdClass::__set_state(array(
'scalar' => '20150521T00:00:00',
'timestamp' => 1432166400,
'xmlrpc_type' => 'datetime',
)),
),
2条答案
按热度按时间ipakzgxi1#
return
运算符implicitly ends the current execution scope。没有给出使用的上下文,但是可以在JSON编码之前将$data
放入array
中并返回它。它可能如下所示:bzzcjhmw2#
您可以在laravel中举这个例子在这里我返回多个价格
$价格= $这个-〉价格;