我正在獲取某些數據通過某人elses腳本形成一個數組我想分片,因爲那裏有很多舊數據,我只需要最新的最新數據。php array_slice無法找到數組
林從XML創建一個這樣的數組:
$result = (object)$SOAP->Export($token, $exportCmd, $admin);
if($result->response->code != APIResponse::Success)
die("Failed to Export");
$exportedXML = $result->exportResult;
$xml = trim(str_replace("Content-type: text/xml", " ", $exportedXML));
$xml = simplexml_load_string($xml);
$json = json_encode($xml);
$response = json_decode($json,TRUE);
如果我打印的迴應,我得到這樣的:
Array (
[R2420] => Array (
[0] => Array ([F2400] => 00200002 [F2425] => 01 [F2426] => 050)
[1] => Array ([F2001] => text [F2400] => 00200002 [F2425] => 00 [F2426] => 060)
[2] => Array ([F2001] => text [F2400] => 00200008 [F2425] => 01 [F2426] => 080)
[3] => Array ([F2001] => text [F2400] => 00200008 [F2425] => 02 [F2426] => 080)
[4] => Array ([F2001] => text [F2400] => 00200026 [F2425] => 00 [F2426] => 150)
[5] => Array ([F2400] => 00200038 [F2425] => 01 [F2426] => 330)
)
)
這一個去5,實際就是到2000左右。我只想要例如最後200.但是,當我使用$output = array_slice($response, -200, 200);
它不會切片什麼,我認爲這是因爲它在數組中的數組,但我該如何切片?
謝謝!
只是一個側面說明:'APIResponse ::成功「表明你正在使用類常量。約定是在UPPER-CASE中編寫常量名,類名和靜態屬性是Ucfirst –