-1

So I hace this pdo statement:

   $sql = "SELECT FD_DATUM_INGEVOERD || ' ' || FT_TIJD_INGEVOERD FROM BANDZENDINGEN WHERE FD_DATUM_INGEVOERD BETWEEN '".$bt."' AND '".$et."' AND FI_GEBRUIKER1='".$uf."' AND FI_AFVOERKANAAL='".$id."'";
   $sfm = $dbh->prepare($sql);
   $sfm->execute();

the result looks like this:

enter image description here

I am trying to get the last element of this array, so I do this:

 $end = array_values(array_slice($array, -1))[0];

and this is the result:

2018-07-10 14:20:09.3290

As you can see this isn't the last element of the array, What am I doing wrong I tried it with the end() function but the result is the same. Please help.

EDIT

last items in the array is 2018-07-10 07:23:11.9510

nordin
  • 161
  • 1
  • 12

2 Answers2

0

Can you try this?

function array_last($array) {
    if (count($array) < 1)
        return null;

    $keys = array_keys($array);
    return $array[$keys[sizeof($keys) - 1]];
}

var_dump(array_last($yourarray));

Or you can try this too.

$last_element=end(array_values($array));

Or

$lastKey=end(array_keys($array));
   var_dump($array[$lastkey]);

Or

var_dump($array[count($array) - 1]);
Jigar
  • 3,055
  • 1
  • 32
  • 51
0

Try

echo $array[count($array) - 1];
sujaypatil
  • 60
  • 1
  • 10