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

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

如何在preg match php代碼上調(diào)用函數(shù)

如何在preg match php代碼上調(diào)用函數(shù)

PHP
郎朗坤 2022-12-23 14:02:46
我有代碼..<?phpfunction word() {     $arr = array("/c/","/b/","/c/");     echo $arr[array_rand($arr)];}$text = "a";if(preg_match("$word()", $text)) {     $result = "found";}else{     $result = "not found";}echo $result;?>如何將函數(shù)調(diào)用word();到preg_match.我想隨機(jī)搜索中的單詞preg_match。我試過了,但沒用。如何修復(fù)此代碼。
查看完整描述

1 回答

?
慕容708150

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

如果你讓你的函數(shù)word()返回隨機(jī)字符串而不是回顯它,你可以通過調(diào)用函數(shù)將它用作任何值。


function word() {

    $arr = array("/c/","/b/","/c/");

    return $arr[array_rand($arr)];

}


if( preg_match(word(), $text) ) {

    $result = "found";

}

else {

    $result = "not found";

}


echo $result;

如果它更清楚,這與將函數(shù)的結(jié)果存儲(chǔ)在變量中并使用它相同。


這些都是一樣的:


// Writing the pattern in place.

preg_match("/a/", $text);


// Storing it in a variable before use.

$to_match = "/a/";

preg_match($to_match, $text);


// Storing it in a variable where the value is returned from a function.

$to_match = word();

preg_match($to_match, $text);


// Using a function directly in the call to `preg_match`.

preg_match(word(), $text);


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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