는 나는이 같은 데이터베이스 테이블에서있어 변수가 :배열에 여러 값을 확인하는 방법은 무엇입니까?
while($r = mysql_fetch_array($query) //The query is just: SELECT * FROM stuff_table WHERE userid='$userid'
{
$stuff = $r['stuff'];
}
물건 변수는 다음과 같습니다 : "자동차, 책, 컴퓨터, 식품"나는 그것을 배열했다 :
을//I used:
$array_of_stuff = explode(",", $stuff); //This gave me an array.
는 지금은 다음과 같이 그 값을 확인하고 싶었 :
if(in_array("cars", $array_of_stuff) && in_array("books", $array_of_stuff))
{
//This line is the problem, I want it to check to see if it has "cars" and "books" in the array but this code is not working for that like it should. Instead of checking and finding both, it just goes on to the next elseif.
echo "Cars and Books";
} elseif(in_array("cars")) {
//
echo "Only cars";
} elseif(in_array("books")) {
echo "Only books";
} else {
echo "Other stuff...";
}
나는이에서 얻을 출력은 다음과 같습니다 대신 "자동차와 책"의 "오직 자동차".
그렇다면 if/elseif 문을 계속하기 전에 코드가 2 개 이상의 값에 대해 배열을 검사하도록하려면 어떻게해야합니까? in_array 함수로 가능합니까?
바르 덤프 :
array(4) { [0]=> string(4) "cars" [1]=> string(6) " books" [2]=> string(10) " computers" [3]=> string(6) " foods" }
코드가 정상적으로 보입니다. 무슨 문제인가? –
'var_dump ($ array_of_stuff)'의 출력을 주시겠습니까? – Lars
@ MДΓΓ БДLL 배열에 2 개의 값을 확인하고 싶지만 그렇지 않습니다. 왜 그런지는 모르겠지만 배열에는 배열에서 찾은 두 개의 값이 있다는 것을 이해하지 못합니다. – randomphp