Jump to content

How to write this code?


salman_ahad@yahoo.com

Recommended Posts

 

PHP function that would return the next to last key (not value) in an array when an array is provided as a parameter.  If there are not two or more elements in the array, the function should return false.

 

What will be the PHP script for this?

 

function nexttolast($array) {
        $size = count($array);
        if($size < 2)
                return false;
        else {
                return array_keys($array,$array[$size-2]);
        }

}

print_r(nexttolast($array));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.