Skip to content

Commit

Permalink
[2.7] [Form] Replaced calls to array_search() by in_array() where is …
Browse files Browse the repository at this point in the history
…no need to get the index

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | none
  • Loading branch information
phansys authored and fabpot committed Feb 5, 2015
1 parent 2e74341 commit c2aeeeb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -144,7 +144,7 @@ public function humanize($text)
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
{
if (is_array($selectedValue)) {
return false !== array_search($choice->value, $selectedValue, true);
return in_array($choice->value, $selectedValue, true);
}

return $choice->value === $selectedValue;
Expand Down
Expand Up @@ -381,7 +381,7 @@ protected function addChoice(array &$bucketForPreferred, array &$bucketForRemain
*/
protected function isPreferred($choice, array $preferredChoices)
{
return false !== array_search($choice, $preferredChoices, true);
return in_array($choice, $preferredChoices, true);
}

/**
Expand Down
Expand Up @@ -111,7 +111,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
// avoid making the type check inside the closure.
if ($options['multiple']) {
$view->vars['is_selected'] = function ($choice, array $values) {
return false !== array_search($choice, $values, true);
return in_array($choice, $values, true);
};
} else {
$view->vars['is_selected'] = function ($choice, $value) {
Expand Down

0 comments on commit c2aeeeb

Please sign in to comment.