note 127901 added to function.in-array

From: Date: Tue, 08 Nov 2022 10:26:51 +0000
Subject: note 127901 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-219856@lists.php.net to get a copy of this message
I got an unexpected behavior working with in_array. I'm using following code: <?php // ... $someId = getSomeId(); // it gets generated/fetched by another service, so I don't know what value it will have. P.S.: it's an integer // The actual data in my edge-case scenario: // $someId = 0; // $anyArray = ['dataOne', 'dataTwo']; if (in_array($someId, $anyArray)) { // do some work } // ... ?> With PHP7.4, in_array returns boolean true. With PHP8.1, in_array returns boolean false. It took me quite some time to find out what's going on. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.131 (proxied: 89.216.25.107) ---- Manual Page -- https://php.net/manual/en/function.in-array.php Edit -- https://main.php.net/note/edit/127901 Del: integrated -- https://main.php.net/note/delete/127901/integrated Del: useless -- https://main.php.net/note/delete/127901/useless Del: bad code -- https://main.php.net/note/delete/127901/bad+code Del: spam -- https://main.php.net/note/delete/127901/spam Del: non-english -- https://main.php.net/note/delete/127901/non-english Del: in docs -- https://main.php.net/note/delete/127901/in+docs Del: other reasons-- https://main.php.net/note/delete/127901 Reject -- https://main.php.net/note/reject/127901 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219856) next »