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!
/** * 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); }