亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 數字文件名排序數組

PHP 數字文件名排序數組

PHP
拉莫斯之舞 2022-01-02 19:34:56
擁有現在創建的代碼和一個包含文本文件的目錄數組,并獲取它們的修改日期,然后降序排序,然后切片并與其他參數單獨回顯每個。我正在更改它以獲取目錄中的文件并按數字文件名排序,然后我希望它降序排序然后切片然后回顯。$files_listed = array();foreach (glob('dir/*.txt') as $quip) {    $files_listed[filemtime($quip)] = $quip;}krsort($files_listed);$master_arc = array_slice($files_listed, 0, 5, true);// arrayforeach($master_arc as $step) {$arc = file($step, FILE_IGNORE_NEW_LINES);// printinclude 'echo.php';}我試過 scandir 并沒有出現$files_listed = array();$dir = 'dir/';$files_listed = scandir($dir, 1);$master_arc = array_slice($files_listed, 0, 5, true);// arrayforeach($master_arc as $step) {$arc = file($step, FILE_IGNORE_NEW_LINES);// printinclude 'echo.php';}我嘗試刪除 filemtime 但它也失敗了,所以我迷路了。$files_listed = array();foreach (glob('dir/*.txt') as $quip) {    $files_listed = $quip;}arsort($files_listed);$master_arc = array_slice($files_listed, 0, 5, true);// arrayforeach($master_arc as $step) {$arc = file($step, FILE_IGNORE_NEW_LINES);// printinclude 'echo.php';}
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

這對我有用。


<?php


$files_listed = array();


foreach (glob('*.txt') as $quip) {

    $files_listed[] = $quip;

}


arsort($files_listed);

$master_arc = array_slice($files_listed, 0, 5, true);


// array

foreach($master_arc as $step) {

print_r($step);


$arc = file($step, FILE_IGNORE_NEW_LINES);

print_r($arc);


}


查看完整回答
反對 回復 2022-01-02
  • 1 回答
  • 0 關注
  • 281 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號