3

I made a website that works perfectly locally. Now I'm trying to publish it online with ploi.io . I get this error:

"Call to undefined function array_key_last()" 3rd line in code

but array_key_last() is a PHP-function.

https://www.php.net/manual/en/function.array-key-last.php

Here is my website link: http://rocallisa.xyz/

if($key === array_key_last($photos))

My server is running PHP 7.3 but this doesn't help.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Niel Agneessens
  • 149
  • 1
  • 2
  • 8

2 Answers2

3

What is the PHP version in the online publication?

In PHP docs:

array_key_last (PHP 7 >= 7.3.0)

https://www.php.net/manual/es/function.array-key-last.php

Is the version of your remote server latter than 7.3?

An alternative: How to get last key in an array?

Dan A.S.
  • 654
  • 8
  • 24
0

Prior to php-7.3, a possible way inline.

$a = (object)["some"=>5, "stuffs"=>3];
echo @end(array_keys( $a ));
// "stuffs"

Notice the error control operator, because end(), or use an intermediary variable.

PHP Notice:  Only variables should be passed by reference 

⚠ The gain in performance and memory footprint is huge using array_key_last() and array_key_first(), consider upgrading to php7.4.

NVRM
  • 11,480
  • 1
  • 88
  • 87