rastlin Posted November 3, 2008 Share Posted November 3, 2008 This has more to do with syntax then anything so I'm hoping it is not in the wrong spot. This is my code, I think I'm thinking is right but doing it the hard way.... if (in_array($check_array[$i],$sess_three)) { //The value is in the array }else{ //Value is not in array so add it and store array into session //something in array add it to the session array $sess_three[] .= $check_array[$i]; }//End of If in-array test Ok I was wondering if I could change that to this and have the same result if (!in_array($check_array[$i],$sess_three)) { //something in array add it to the session array $sess_three[] .= $check_array[$i]; }//End of If in-array test Hope I'm not bothering ya'll to much, hope to hear from you soon and many thanks Stephen Link to comment https://forums.phpfreaks.com/topic/131215-solved-simple-in_array-help/ Share on other sites More sharing options...
rhodesa Posted November 3, 2008 Share Posted November 3, 2008 yes...if you don't want to do anything if it's already in the array, then your approach is correct. one thing i will point out though, is there shouldn't be a . before the = if (!in_array($check_array[$i],$sess_three)) { //something in array add it to the session array $sess_three[] = $check_array[$i]; }//End of If in-array test Link to comment https://forums.phpfreaks.com/topic/131215-solved-simple-in_array-help/#findComment-681226 Share on other sites More sharing options...
rastlin Posted November 3, 2008 Author Share Posted November 3, 2008 Ok but would that still add it the the array with the values that are in it? $sess_three[] = $check_array[$i]; I always thought you had to add the . to keep the current content of the array while adding the new value on the end, if I'm wrong please let me know.... many thanks Stephen Link to comment https://forums.phpfreaks.com/topic/131215-solved-simple-in_array-help/#findComment-681230 Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 Yeah, you do NOT need the . before the equals sign. The [] on the end of the array name already creates the new element for you. Link to comment https://forums.phpfreaks.com/topic/131215-solved-simple-in_array-help/#findComment-681234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.