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. Link to comment https://forums.phpfreaks.com/topic/94984-put-into-array/ Share on other sites More sharing options...
Barand Posted March 7, 2008 Share Posted March 7, 2008 $array[$key] = $value; Link to comment https://forums.phpfreaks.com/topic/94984-put-into-array/#findComment-486555 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 Link to comment https://forums.phpfreaks.com/topic/94984-put-into-array/#findComment-486576 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. Link to comment https://forums.phpfreaks.com/topic/94984-put-into-array/#findComment-486599 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"; Link to comment https://forums.phpfreaks.com/topic/94984-put-into-array/#findComment-486604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.