简体   繁体   中英

in_array() -- What am I doing wrong?

I'm banging my head against the wall here.

I have some simple code that goes something like this (I've simplified it greatly for simplicity's sake):

$myValue = 1;

$myArray[0] = 2;
$myArray[1] = 3;
$myArray[2] = 1;

if(in_array($myValue, $myArray, true)) {
   do something;
}
else {
   do something else;
}

I always get the 'else.' Am I doing something wrong here?

It will return "Yes". Do & else are PHP keyword. Echo Something.. It Will Come

<?
$myValue = 1;

$myArray[0] = 2;
$myArray[1] = 3;
$myArray[2] = 1;

if(in_array($myValue, $myArray, true)) 
{
   echo "Yes";
}
else 
{
   echo "No";
}
?>

Otherwise, if you use 'do' or 'else' keyword, Parse error: syntax error, unexpected '}', expecting while (T_WHILE) error will come.

For more info, read this http://www.w3schools.com/php/func_array_in_array.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM