Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have following arrays.

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

I want to do something like this .

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";
}

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

Is this what you mean?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...