inArray() 공개 정적인 메소드

in_array itself has some PHP flaws regarding cross-type comparison: - in_array('50x', array(40, 50, 60)) would be true! - in_array(50, array('40x', '50x', '60x')) would be true!
public static inArray ( mixed $needle, array $haystack ) : boolean
$needle mixed
$haystack array
리턴 boolean Success
예제 #1
0
 /**
  * UtilityTest::testInArray()
  *
  * @covers ::inArray
  * @return void
  */
 public function testInArray()
 {
     $res = Utility::inArray(2, [1, 2, 3]);
     $this->assertTrue($res);
     $res = Utility::inArray(4, [1, 2, 7]);
     $this->assertFalse($res);
     $res = Utility::inArray('2', [1, 2, 3]);
     $this->assertTrue($res);
     $res = Utility::inArray(2, ['1x', '2x', '3x']);
     $this->assertFalse($res);
     $res = Utility::inArray('3x', ['1x', '2x', '3x']);
     $this->assertTrue($res);
     $res = Utility::inArray(3, ['1', '2', '3']);
     $this->assertTrue($res);
     $res = Utility::inArray('2x', [1, 2, 3]);
     $this->assertFalse($res);
 }