If i wish to check whether a value is already stored in an array or not Then how can i chekc that? Is this any function is there in php?
Use in_array() <?php $color_array = array("blue", "red", "orange"); if (in_array("black", $color_array)){ echo("Black exists in color array"); } else{ echo("Black does not exists in color array"); } ?> PHP:
in_array is fine for regular sites. However, it is more efficient to use isset. Sometimes much more efficient when you enter into thousands/millions of elements. The reason isset is more efficient than is_array is that it does not loop through each element to check if it exists, but rather does direct address check. <?php $colorArray = array('blue', 'red', 'orange'); if ( isset($colorArray['black']) ) { echo 'Black exists in color array'; } else { echo 'Black does not exists in color array'; } PHP:
The code you've posted isn't relevant at all. To borrow from php.net: So in this instance, if using on an array, you'd basically be checking if a value exists for an array key. isset($colorArray['blue']) would return false, as it isn't set - though isset($colorArray[0]) would return true, since $colorArray[0] is set, and it has a value of 'blue'.