搜索在VS文本搜索数组....哪一个更好的效率? [英] Efficiency of Searching an Array Vs Searching in Text.... Which is Better?
问题描述
我有(整数)编号的,对此我保存为文本,如
I have a List of (integer)ID's, which i am storing as text, like
23;45;67;12;332;783;123;33;15;87;41;422;88;58;
现在我用PHP的工作,我想检查是否有特定的ID在该文本已经存在,我有在爆炸功能,它可以给我号的阵列,然后我可以使用 in_array 功能,或者我可以只使用 strpos 功能设置为查找文本
now i am working with PHP, i want to check if a particular ID already exists in that TEXT, i have the explode function, which can give me an array of numbers, and then i can use the in_array function, alternatively i can just use the strpos function to find in text.
那么,哪一个会的更有效 accourding给你?
so which one will be more efficient accourding to you ?
非常感谢您抽出时间来阅读。
Thanks a lot for taking time to read this.
推荐答案
如果你需要做的就是查找一个ID,那么 strpos()
将更加高效,因为所有它需要做的就是找到 ID的发生;
,而爆炸()
会做很多更重要的是,更不用说 in_array昂贵的调用()
。
If all you have to do is look up a single ID, then strpos()
will be more efficient, because all it has to do is find an occurrence of id;
, whereas explode()
will do a lot more than that, not to mention the costly call to in_array()
.
这篇关于搜索在VS文本搜索数组....哪一个更好的效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!