我有以下数组。
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";
}
以上代码无效。请帮帮我。如何在foreach循环中动态放置条件。
答案 0 :(得分:0)
这是你的意思吗?
foreach ($values as $value) {
if (!in_array($value[0], array('Cash', 'Credit'))) {
echo 'Neither cash nor credit';
}
}
答案 1 :(得分:-1)
试试这个
foreach ($array as $values) {
if($values[0] != "cash" && $values[0] == "credit"){
echo "It is a credit ";
}
else if($values[1] != "credit" && $values[0] == "cash"){
echo "it is a cash"."<br>";
}