Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
希望我措辞正确。
如果我有一些变量称为$foo_bar $foo_barbar $foo_barbarbar
$foo_bar
$foo_barbar
$foo_barbarbar
无论如何使用 preg_match/[A-Z]|[0-9]/i来替换 bar、barbar、barbarbar?
/[A-Z]|[0-9]/i
您可以通过循环 $GLOBALS 来做到这一点
但请注意,这是详尽无遗的
foreach($GLOBALS as $name => $val){ if(preg_match('/foo[A-Za-z0-9_]*bar/',$name)){ if(is_array($val)){ print_r($val); } else{ echo $val; } } }