Skip to content
Advertisement

in_array vs strpos for performance in php

I am logging in users via windows authentication and then storing that user’s rights in a session variable. I use a delimited method of rights storage in a database i.e:

JavaScript

so my question is should I;

JavaScript

OR

JavaScript

Bit of a OCD question as I presume the difference will be pretty much negligible for what I am doing but which would be the faster (use less resources) method?

Any answers appreciated except ones that insult my method of rights storage!

Advertisement

Answer

strpos is the fastest way to search a text needle, per the php.net documentation for strstr():

If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead.1

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement