Jump to content

in_array()


Omzy

Recommended Posts

I have a checkbox array called 'selection' ($_POST['selection'])

 

If I want to check for a value against the values held in the array, is it best to use:

 

1) if (in_array($value, $_POST['selection']))

 

or:

 

2) if (in_array($value, array_values($_POST['selection'])))

 

Form my testing both of these methods work. Also I found that method 1 does not match against the array INDEX/KEY - is this the correct behaviour?

Link to comment
https://forums.phpfreaks.com/topic/170319-in_array/
Share on other sites

I have a checkbox array called 'selection' ($_POST['selection'])

 

If I want to check for a value against the values held in the array, is it best to use:

 

1) if (in_array($value, $_POST['selection']))

 

or:

 

2) if (in_array($value, array_values($_POST['selection'])))

 

Form my testing both of these methods work.

You can use either method. Both will work just fine. However the 2nd method seems unnecessary.

Link to comment
https://forums.phpfreaks.com/topic/170319-in_array/#findComment-898477
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.