我有点陷入困境,代码比这大得多,但这大致就是这样......
<?php
$other = 'white';
$array = array('red', 'blue', 'red', 'red', 'red');
foreach($array[1] as $match) //OR $match = $other;
{
//Core Area
if($match == 'red') { echo 'RED!'; }
if($match == 'blue') { echo 'BLUE!'; }
if($match == 'white') { echo 'white!'; }
}
?>
像现在这样,$other
不碍事就无法进入核心区域foreach
。另一种方法是克隆——通过复制粘贴——到另一个地方。...这不会很好地工作...我尝试将该区域放在一个函数中,但没有许多全局值,它似乎不是一个可行的选择。有什么办法可以在foreach
和之间切换=
吗?