-1
$testarray = array("Computer", 30.00, 123, 321");


if(in_array('Computer' , $testarray)){
  echo "yes!";
}else{
  echo "no!";
}

Guys, my in_array doesn't display yes output when in the array I have the computer value inside. Why is that so?

4
  • 4
    If you happy and you know it Syntax error! Commented Feb 18, 2014 at 9:13
  • 1
    Remove the " after 321 and try again. Commented Feb 18, 2014 at 9:14
  • Yes! extra " in the array definition after 321. Remove it, and it works. Commented Feb 18, 2014 at 9:14
  • 2
    @StephanB be careful when editing code in questions, because what you edit may be part of OPs problem rendering possible answers useless and leaving possible future readers in a wtf state. Commented Feb 18, 2014 at 9:16

3 Answers 3

2

You have a syntax error in the first line, change it to

$testarray = array("Computer", 30.00, 123, "321");

or

$testarray = array("Computer", 30.00, 123, 321);

depending on if you whant the last value to be integer or string

2
  • Fixed, but it still display no instead of yes Commented Feb 18, 2014 at 9:16
  • @user3322610 The above works just fine. So either you didn't share your actual code or something else is wrong. Commented Feb 18, 2014 at 9:21
0

You try this?

$testarray = array("Computer", 30.00, 123, 321);
if(in_array('Computer' , $testarray)){
   echo "yes!";
}else{
   echo "no!";
}

Just a syntax error. Enable PHP display_errors to see this error.

0
<?php
$testarray = array("Computer", 30.00, 123, 321);


if(in_array('Computer',$testarray )){
  echo "yes!";
}else{
  echo "no!";
}
?>

Your syntax is be wrong!!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.