I have a series of arrays and usually if i want to check if a value exists i iterate throu the array, use an if statement inside the foreach block then break or return, but recently I decided to use array_flip to flip the array then check if the key exists with isset:
<?php
$arr = array(1, 0, 'yes', 'no', 'on', 'off' /* more keys */);
/*
foreach($arr as $value) {
if ($value === 'on') { return 'xxx'; }
}
*/
//Alternative
$arrFlipped = array_flip($arr);
if (isset($arrFlipped['on'])) { return xxx; }
?>
The arrays are made from safe data, not user input, so the values would always be valid keys.
I'd like to know if this appoach is ok, what are the advantages and disadvantages?, wich one is faster or waste less resources? Sorry for my english... thanks!
Edit: OP asks for multiple values