首页 > 解决方案 > 为什么这个 if 语句返回 true?

问题描述

为什么这会返回真实?Party Bounce 和 Slide 13 x18 不在 if 语句中?

print_r($btypes);
        //Array ( [0] => 11x13 Red and Yellow 2 [1] => Party Bounce and Slide 13 x 18 )

        if(in_array("12x15 Purple and Yellow 2" || "11x13 Red and Yellow 1" || "12x15 Yellow and Purple old" || "11x13 Red and Yellow 2" || "12x15 Purple and Yellow 1" ,$btypes) && 
        in_array("Bootcamp Obstacle Course" ||  "Terminator Torment Obstacle Course" || "Lizard Obstacle Course" || "Bugs Obstacle Course" || "Nemo Obstacle Course",$btypes))
        {
            return "Standard Bouncy Castle and an Obstacle Course";
        }

谢谢你的帮助

标签: php

解决方案


更易于管理且更重要的快速解决方案……阅读。

$attributes = [
    "12x15 Purple and Yellow 2", 
    "11x13 Red and Yellow 1", 
    "12x15 Yellow and Purple old",
    "11x13 Red and Yellow 2", 
    "12x15 Purple and Yellow 1"
];

$types = [
    "Bootcamp Obstacle Course",
    "Terminator Torment Obstacle Course",
    "Lizard Obstacle Course",
    "Bugs Obstacle Course",
    "Nemo Obstacle Course"
];

if(array_intersect($btypes, $attributes) !== [] && array_intersect($btypes, $types) !== []){
    return "Standard Bouncy Castle and an Obstacle Course";
}

推荐阅读