slice - php array_slice cant find array -


im getting data trough elses script forms array want slice because there lot of old data in there , need latest newest data.

im creating array xml this:

    $result = (object)$soap->export($token, $exportcmd, $admin);      if($result->response->code != apiresponse::success)       die("failed 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); 

if print response this:

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 ) ) ) 

this 1 goes 5, actual 1 till 2000. want example last 200. when use $output = array_slice($response, -200, 200); wont slice off, think thats because array in array, how slice that?

thanks!

you just

$output = array_slice($response[0], -200, 200); 

if sure first element in array wanted.

just make sure wrap in check $response[0] exists.

$output = false; if (!empty($response[0]))     $output = array_slice($response[0], -200, 200); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -