Jump to content

use another function instead of in_array


mehdi_php

Recommended Posts

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

 

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
...?
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.