我使用從Bittrex的API,讀取JSON,然後用一個循環通過每個迴路得到的信息,我需要PHP for each循環
一切正常返回只有某些元素。這裏是代碼:
foreach($return[result] as $x=>$x_value){
extract($x_value);
echo $OrderUuid." " .$closedDate ." " .$closedTime ." " .$Quantity." " .$Price." " . $PricePerUnit * 100000000 ." <br>";
}
不過,我想這樣做,因爲我把它放到表分頁是我需要能夠怎麼只能隨聲附和出像1-5再下一個頁面的結果將是6-11等等
我知道計數已經通過使用它,它返回的結果量。
$thisManyResults=count($return[result]);
我知道我需要記住,索引也是從零開始的。
循環讓我感到非常困惑,請給出一個解釋,讓新手環繞他的頭。謝謝
編輯:
foreach($return[result] as $x=>$x_value){
extract($x_value);
$str66 = str_replace('T', ' ', $TimeStamp);
$newarray = explode(" ", $str66);
$date =date_create($newarray[0]);
$closedDate = date_format($date,"m/d/Y");
$closedTime = date("g:i:s a", strtotime($newarray[1]));
// echo $OrderUuid." " .$closedDate ." " .$closedTime ." " .$Quantity." " .$Price." " . $PricePerUnit * 100000000 ." <br>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'>". $Quantity ." </td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $Price." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $PricePerUnit * 100000000 ." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $closedDate." </center></td>";
echo "<td style='text-decoration:none;color:#000000;font-weight:normal'><center>". $closedTime." </center></td></tr>";
}
但這顯示所有結果0-22(23結果)我需要能夠僅在表0顯示直通5或6直通10
我實際上已經將分頁算出來了。我只需要能夠僅從結果#5到#10顯示(回顯)... api沒有開始和結束,所以我必須每次都調用它。 –
即時嘗試添加數組切片現在更新的代碼上面 –
我的代碼只是一個例子,你不需要從API開始和結束,如果你有所有的結果已經存儲在數組中 –