PHP - 代码之间切换困难
我遇到了一个比这大得多的代码的困境,但这大致是这样的...
<?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
和 =
之间切换?
I'm in a bit of a predicament with a much larger code than this, but this is roughly how it is...
<?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!'; }
}
?>
As it is now, $other
cannot enter the core area without the foreach
being in the way. The alternative being cloning -- via copy n' paste -- to another place. ...Which wont work very well... I've tried placing the area in a function, but without many of global values, it does not seem like a viable option. Is there any way to switch between the foreach
and the =
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在
$other
位于数组中,因此它将位于您在循环中比较的内容列表中。为什么你想要这个或者你真正想要的东西在我的脑海中飞过。
Now
$other
is in the array so it'll be in the list of things you compare within your loop.Why you want this or what you're really asking is flying over my head.
?>
或者:
?>
Alternatively: