[php-src] Issue #8775: array_search() DOES NOT check anything in position 0
| From: | sujyrokimora | Date: | Tue, 14 Jun 2022 09:07:15 +0000 |
| Subject: | [php-src] Issue #8775: array_search() DOES NOT check anything in position 0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241727@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8775
Author: sujyrokimora
### Description
The following code:
```php
$array1=['289','290','297'];
$array2=['289','290','297'];
$num=0;
while ($num<count($array1))
{
echo print_r($array1,true);
echo '<br>';
echo print_r($array2,true);
$t=$array1[$num];
echo '<br>';
echo $t;
echo '<br>';
if (array_search($t,$array2,TRUE))
{
echo 'This matched: '.$array1[$num];
}
echo '<br>';
$num++;
}
```
Resulted in this output:
```
Array ( [0] => 289 [1] => 290 [2] => 297 )
Array ( [0] => 289 [1] => 290 [2] => 297 )
289
Array ( [0] => 289 [1] => 290 [2] => 297 )
Array ( [0] => 289 [1] => 290 [2] => 297 )
290
IThis matched: 290
Array ( [0] => 289 [1] => 290 [2] => 297 )
Array ( [0] => 289 [1] => 290 [2] => 297 )
297
This matched: 297
```
But I expected this output instead:
```
Array ( [0] => 289 [1] => 290 [2] => 297 )
Array ( [0] => 289 [1] => 290 [2] => 297 )
289
This matched: 289
Array ( [0] => 289 [1] => 290 [2] => 297 )
Array ( [0] => 289 [1] => 290 [2] => 297 )
290
IThis matched: 290
Array ( [0] => 289 [1] => 290 [2] => 297 )
Array ( [0] => 289 [1] => 290 [2] => 297 )
297
This matched: 297
```
https://3v4l.org/r5tN9#v8.1.7
### PHP Version
PHP 8.1.2
### Operating System
Windows 10- 10.0.19044 N/A Build 19044