Link to home
Start Free TrialLog in
Avatar of dolythgoe
dolythgoe

asked on

php in_array efficiency

Hello,

I'm a little concerned over computing cost of a feature that I hope some people can give me reassurance :)

I have a sphinx search on documents with some features to both 'favorite' and 'mark as read' on each result returned.

These features which are available require a store of all items marked as either favorited or mark as read.

Favorited max cap is 2000 and mark as read can go 2000+

My theory is to store all the doc_ids in 2 arrays upon login. So my first thought is, is that dangerous to store so many values in a $_SESSION?

Next thought is when the results are returned, I need to run something like the below:

if(in_array($doc_id, $_SESSION['favorites_array']))
{
	$favorite_link = 'Favorited';
}
else
{
	$favorite_link = '<a href="addtofavorites.php">Add to Favorites</a>';
}

if(in_array($doc_id, $_SESSION['read_array']))
{
	$read_link = 'Marked as Read';
}
else
{
	$read_link = '<a href="addtofavorites.php">Mark as Read</a>';
}

Open in new window


Just need some expert opinion really on the best way of achieving this - trying to avoid db queries where I can

$doc_id's are INTs

Cheers
SOLUTION
Avatar of amigura
amigura
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dolythgoe
dolythgoe

ASKER

Good to hear :) - and the in_array() processing?

There's 24 results per page so php has to either lookup per result or there might be a way of getting the 24 id's and compare array against array to produce an array of matches if you see what I mean. Then compare the much smaller array of matches with each listing...does that make sense?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome, gotta love php's ability to have a function for everything!

Cheers guys