BobbyDank
BobbyDank

Reputation: 329

Getting a single array out of another array

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.

Upvotes: 0

Views: 62

Answers (3)

BobbyDank
BobbyDank

Reputation: 329

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

Upvotes: 0

Susheel
Susheel

Reputation: 1679

let name your array as $long_arr

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

Upvotes: 0

Maxim Khan-Magomedov
Maxim Khan-Magomedov

Reputation: 1336

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.

Upvotes: 2

Related Questions