Skip to content

Commit

Permalink
Only function now doesn't include item with key 0 in every result
Browse files Browse the repository at this point in the history
  • Loading branch information
DusanKasan committed Jun 3, 2016
1 parent 6784a9f commit fafbcf8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@

##8.1.0
- ReplaceByKeys function added

##8.1.1
- Fixed bug: the only function always included the item with key equal to zero in the result. Caused by comparing string == 0. Also affected extract.
2 changes: 1 addition & 1 deletion src/collection_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ function only($collection, $keys)
return filter(
$collection,
function ($value, $key) use ($keys) {
return in_array($key, $keys);
return in_array($key, $keys, true);
}
);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/spec/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,9 @@ function it_can_extract_data_from_nested_collections()
],
'c' => [
'b' => 5
],
[
'a'
]
]
];
Expand Down

0 comments on commit fafbcf8

Please sign in to comment.