如果在foreach内部条件则为php [英] Php if condition inside foreach

查看:238
本文介绍了如果在foreach内部条件则为php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数组.

Array
(
    [0] => Array
        (
            [0] => Cash
            [1] => 91.16
        )
    [1] => Array
        (
            [0] =>Credit
            [1] => 61.48
        )
)

我想做这样的事情.

foreach ($value as $values) {
// Where $values is the above array . I want to traverse array dynamically and put if condition .
if($values[0][0] != "Cash")
echo "Cash";
}

上面的代码不起作用.请帮助我.如何在ifeach循环内动态放置条件.

The above code does not working . Please help me on this . How can I place if condition dynamically inside foreach loop.

推荐答案

这是您的意思吗?

foreach ($values as $value) {
  if (!in_array($value[0], array('Cash', 'Credit'))) {
    echo 'Neither cash nor credit';
  }
}

这篇关于如果在foreach内部条件则为php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆