android6011 Posted March 7, 2008 Share Posted March 7, 2008 I have an empty array to start with ($array=array() and I have an if statement that checks if a string is in the array using array_key_exists. Now if it doesnt exist in the array I want to insert it into the array. how do I do that? I only know how to define an array not insert into an array during a loop. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 7, 2008 Share Posted March 7, 2008 $array[$key] = $value; Quote Link to comment Share on other sites More sharing options...
android6011 Posted March 7, 2008 Author Share Posted March 7, 2008 hmm i tried that but it wasnt working.... maybe something before that was throwing it off ill check into it Quote Link to comment Share on other sites More sharing options...
android6011 Posted March 8, 2008 Author Share Posted March 8, 2008 how can i see if an element already exists in an array?? I think that is waht is hanging up my script. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 If you want to know if the key exists if (isset($array[$key])) echo "exists"; For the value if (in_array($val, $array)) echo "exists"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.