change last key name from array in php

Posted by robertdd on Stack Overflow See other posts from Stack Overflow or by robertdd
Published on 2010-04-19T23:29:14Z Indexed on 2010/04/19 23:33 UTC
Read the original article Hit count: 236

Filed under:
|
|

i want to be able to change the last key from array i try with this function i made:

function getlastimage($newkey){
    $arr = $_SESSION['files'];
    $oldkey = array_pop(array_keys($arr));
    $arr[$newkey] = $arr[$oldkey];
    unset($arr[$oldkey]);
    $results = end($arr);
    //echo json_encode($results);
    print_r($arr);
}

if i call the function getlastimage('newkey') it change the key!but after if i print the $_SESSION the key is not changed? why this?

© Stack Overflow or respective owner

Related posts about array

Related posts about php