From 61a3f8bb95111fade6eace55c071c43da0cc75d9 Mon Sep 17 00:00:00 2001 From: Djordy Koert Date: Sat, 17 Aug 2024 15:03:07 +0200 Subject: [PATCH] fix(#2336): keep original index key (#2337) | Q | A | |---------------|---------------------------------------------------------------------------------------------------------------------------| | Bug fix? | yes | | New feature? | no | | Deprecations? | no | | Issues | Fix #2336 | The original implementation lost the original key index because it created a new array (with `array_column`). https://3v4l.org/kWPt7#v8.3.10 --- src/OpenApiPhp/Util.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/OpenApiPhp/Util.php b/src/OpenApiPhp/Util.php index 9c967b731..5dca4db7d 100644 --- a/src/OpenApiPhp/Util.php +++ b/src/OpenApiPhp/Util.php @@ -273,14 +273,20 @@ public static function searchCollectionItem(array $collection, array $properties /** * Search for an Annotation within the $collection that has its member $index set to $value. * - * @param mixed[] $collection - * @param mixed $value The value to search for + * @param OA\AbstractAnnotation[] $collection + * @param mixed $value The value to search for * * @return false|int|string */ public static function searchIndexedCollectionItem(array $collection, string $member, $value) { - return array_search($value, array_column($collection, $member), true); + foreach ($collection as $i => $child) { + if ($child->{$member} === $value) { + return $i; + } + } + + return false; } /**