0

I have some code that is generating this array (broke it up for easy reading):

Array ( [0] => 78 ) 78 
Array ( [0] => 78 [1] => 75 ) 75 
Array ( [0] => 78 [1] => 75 [2] => 72 ) 72 
Array ( [0] => 78 [1] => 75 [2] => 72 [3] => 68 ) 68 
Array ( [0] => 78 [1] => 75 [2] => 72 [3] => 68 [4] => 65 ) 65 
Array ( [0] => 78 [1] => 75 [2] => 72 [3] => 68 [4] => 65 [5] => 62 ) 62 
Array ( [0] => 78 [1] => 75 [2] => 72 [3] => 68 [4] => 65 [5] => 62 [6] => 59 ) 59 
Array ( [0] => 78 [1] => 75 [2] => 72 [3] => 68 [4] => 65 [5] => 62 [6] => 59 [7] => 56 ) 56 
Array ( [0] => 78 [1] => 75 [2] => 72 [3] => 68 [4] => 65 [5] => 62 [6] => 59 [7] => 56 [8] => 37 ) 37 
Array ( [0] => 78 [1] => 75 [2] => 72 [3] => 68 [4] => 65 [5] => 62 [6] => 59 [7] => 56 [8] => 37 [9] => 36 ) 36

What I need is the last array. The one that has all the numbers individually stored. How can I do this? In php btw.

3
  • those are individual arrays as is. is there some other array that contains these that you're not showing? Commented May 15, 2013 at 21:54
  • Tell us how you are getting this list of arrays first Commented May 15, 2013 at 21:55
  • If you use count($your_array) it counts the rows well or not??...if count is good then you can retrieve the last row something like $row = $your_array[count($your_array)-1]; Commented May 15, 2013 at 21:58

3 Answers 3

2

Try array_pop($array). It will pop the last element from array and return it.

update:

$buffer = array();
foreach ($arrays as $array) {
    $buffer = array_pop($array);
}

I think this is what you mean.

Sign up to request clarification or add additional context in comments.

1 Comment

If you need to keep arrays intact, use end($array); echo current($array);
0

let name your array as $long_arr

$target_array = array_values($long_arr); 
var_dump($target_array);

Comments

0

This comment did it for me:

If you use count($your_array) it counts the rows well or not??...if count is good then you can retrieve the last row something like $row = $your_array[count($your_array)-1]; – Robert Rozas 18 hours ago

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.