我通过别人的脚本获取了一些数据,这些脚本形成了我想要切片的数组,因为那里有很多旧数据,我只需要最新的数据。
我从 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);
它时不会切掉任何东西,我认为那是因为它是数组中的一个数组,但是我该如何切片呢?
谢谢!