mehdi_php Posted October 15, 2008 Share Posted October 15, 2008 hi . i have this code for counting each profile views and avoid to increment by refresh but i have problem here . since array_merge start with his own index i can't determine my specific id is in the array or not . so i want to what function can i use to determine a value in array or not . instead of using in_array function . <?php //product view counter: //init array $ID = array(); $ID[$pid] = $pid ; //debug echo '<pre>' ; print_r($ID); echo '</pre>' ; //init session if(isset($_SESSION['ID'])): $_SESSION['ID'] = array_merge($_SESSION['ID'] , $ID ) ; else: $_SESSION['ID'] = $ID ; endif; //debug echo '<pre>' ; print_r($_SESSION['ID']); echo '</pre>' ; //check for sessions if(!in_array($_SESSION['ID'] , $ID[$pid])): //ok session not exist go ahead query db $num = $db->get_var("select xviewnum from xxprofile where xprofileid='$pid'") ; $num += 1 ; $db->query("update xxprofile set xviewnum='$num' where xprofileid='$pid'") ; endif; //END product view counter ?> tanks for helping Quote Link to comment https://forums.phpfreaks.com/topic/128505-use-another-function-instead-of-in_array/ Share on other sites More sharing options...
Zane Posted October 15, 2008 Share Posted October 15, 2008 you can always pull a foreach on it and set a boolean foreach($array as $value) $in_array = $value == "Search Term" ? true : false; if($in_array) { //do stuff .... .............. } else { .....................//do stuff ...? } Quote Link to comment https://forums.phpfreaks.com/topic/128505-use-another-function-instead-of-in_array/#findComment-665981 Share on other sites More sharing options...
ghostdog74 Posted October 15, 2008 Share Posted October 15, 2008 you can use array_values() Quote Link to comment https://forums.phpfreaks.com/topic/128505-use-another-function-instead-of-in_array/#findComment-665982 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.