[英]Optimal way of checking if any of multiple strings are non-empty (in php)
I have several strings which may or may not be empty. 我有几个字符串,可能是空的也可能不是空的。 If any of them are non-empty, a mysql insertion should be called.
如果其中任何一个非空,则应调用mysql插入。
I've coded it simply, but was thinking about the fastest method of testing if ANY of them is non-empty. 我已经对其进行了简单的编码,但是正在考虑最快的测试方法是否其中的任何一个都是非空的。
$a = something;
$b = something;
$c = something;
Options 选项
I would do something like this: 我会做这样的事情:
if (!$a || !$b || !$c){
...
}
There is no overhead of a function like strlen
etc. The !
没有像
strlen
这样的函数的开销!
is good bet there. 在那里打赌好。
Wouldn't one way of finding out be testing by generating, let's say, at set of 1000 random strings and traverse that set for each option? 假设不是通过生成1000个随机字符串并遍历每个选项的设置来找出测试的方法吗? I assume it's quite a naive way and reading about the native code for each function would generate a more thorough answer, but still, it's easy :)
我认为这是一种幼稚的方式,阅读每个函数的本机代码将产生更彻底的答案,但是仍然很容易:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.