cgm225 Posted August 1, 2008 Share Posted August 1, 2008 I need an IF statement/function that does the following: checks if an array contains a specific key, and, if so, replaces the key's value with a new provided value, but, if not, then it creates a new key (the one we were looking for) and sets it to the new value. Any ideas? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/117709-checking-for-key-in-array/ Share on other sites More sharing options...
libertyct Posted August 1, 2008 Share Posted August 1, 2008 array_key_exists <?php $search_array = array('first' => 1, 'second' => 4); if (array_key_exists('first', $search_array)) { echo "The 'first' element is in the array"; } ?> then if key does not exist in array add it Link to comment https://forums.phpfreaks.com/topic/117709-checking-for-key-in-array/#findComment-605440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.