正在尝试使用unset删除数组中的值.PHP


Trying to delete value in array, using unset. PHP

$file读取元素到数组,返回array[0]的值,然后删除元素并将数组保存到文件取消设置不起作用,为什么
这是代码:
list.txt-文件(1kb)10行

    function files($files)
    {
        $list = array();
        $list = file($file) or die('read error');
        print_r($list); //debug

        unset($list[0]);
        $f = fopen($file, 'w+');
        flock($f, LOCK_EX);
        foreach ($list as $string) {
            fwrite($f, $string);
        }
        print_r($list); // debug
        flock($f, LOCK_UN);
        fclose($f);
return $s = ($list[0]);
}

在未设置语句之前返回一个值:

function files()
{ 
    $list = array();
    $list = file($file) or die('read error');
    print_r($list); //debug
    return $s = ($list[0]);
    // Every statement after this line wouldn't be called, because you
    // already returned
    unset($list[0]);
}

尝试

$result = $list[0];
// And at the end of your function
return $result;