第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在列出這些項(xiàng)目之前顯示符合特定條件的文件/項(xiàng)目的計(jì)數(shù)

在列出這些項(xiàng)目之前顯示符合特定條件的文件/項(xiàng)目的計(jì)數(shù)

PHP
三國(guó)紛爭(zhēng) 2022-06-11 18:15:02
我似乎無(wú)法在任何地方找到答案。我正在嘗試計(jì)算 FTP 文件夾中滿足特定條件的文件數(shù)。我正在使用以下內(nèi)容:/* * Filename examples:  * Store Evaluation_10950_2019-12-03_6980.pdf * Store Survey_13532_2019-11-29.pdf */$file_list = ftp_nlist($ftp_connection, "."); $currentDate = date('Y-m');$countFiles = count($file_list);// Title of Completed Evaluatonsecho '<strong>'.$countFiles.' Completed Evaluations:</strong><br><br>'; foreach($file_list as $file) {//Only get Current Month PDF files    if ((strpos($file, '.pdf') !== false) && (strpos($file, 'Store Evaluation') !== false) && (strpos($file, $currentDate) !== false)) {        // Remove Store Evaluation_ from string        $strippedEvals1 = ltrim($eval, 'Store Evaluation_');        // Remove store number from string        $strippedEvals2 = strstr($strippedEvals1, '_');        // Remove _ from string        $strippedEvals3 = str_replace('_','',$strippedEvals2);        // Remove everything after the date in string        $strippedEvalDate = substr_replace($strippedEvals3 ,"", -8);         // Get just the store number        $strippedEvalStoreNum = substr($strippedEvals1, 0, strpos($strippedEvals1, "_"));         // Print store number and date        echo "<strong>".$strippedEvalStoreNum."</strong> (".$strippedEvalDate.")<br>";    }}我能夠根據(jù)我指定的條件列出所有文件;但是,現(xiàn)在我想數(shù)一數(shù)并說(shuō)出頂部有多少。上面的代碼顯然是在沒(méi)有條件的情況下輸出了文件夾中所有文件的個(gè)數(shù)。我試圖$countFiles = count(strpos($file_list, '.pdf'));只測(cè)試一個(gè)條件,但這沒(méi)有產(chǎn)生任何結(jié)果。解決這個(gè)問(wèn)題的正確方法是什么?
查看完整描述

1 回答

?
青春有我

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊

count()不是在循環(huán)時(shí)回顯條件,而是可以將其存儲(chǔ)在一個(gè)數(shù)組中,然后在數(shù)組的末尾用 a 輸出它$output:


$output = array(); //create an empty array to store our output


foreach($file_list as $file) {

//Only get Current Month PDF files

    if ((strpos($file, '.pdf') !== false) && (strpos($file, 'Store Evaluation') !== false) && (strpos($file, $currentDate) !== false)) {

        // Remove Store Evaluation_ from string

        $strippedEvals1 = ltrim($eval, 'Store Evaluation_');

        // Remove store number from string

        $strippedEvals2 = strstr($strippedEvals1, '_');

        // Remove _ from string

        $strippedEvals3 = str_replace('_','',$strippedEvals2);

        // Remove everything after the date in string

        $strippedEvalDate = substr_replace($strippedEvals3 ,"", -8); 

        // Get just the store number

        $strippedEvalStoreNum = substr($strippedEvals1, 0, strpos($strippedEvals1, "_")); 

        // Print store number and date

        $output[] =  "<strong>".$strippedEvalStoreNum."</strong> (".$strippedEvalDate.")"; //add to array instead of echo

    }

}


echo '<strong>'.count($file_list).' Completed Evaluations</strong><br><br>'; 


echo '<strong>'.count($output).' Evaluations Met My Conditions:</strong><br><br>'; //echo the number of files that met the conditions


echo implode('<br/>', $output); //echo the converted file names


查看完整回答
反對(duì) 回復(fù) 2022-06-11
  • 1 回答
  • 0 關(guān)注
  • 92 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)