Fan*_*III 2 php arrays search boolean return
if (array_search($soca, $user_socs))
Run Code Online (Sandbox Code Playgroud)
我知道这将通过输入变量和数组来搜索数组,但我想知道是否可以使其返回 true,因为由于它不返回 true,所以我的 if 语句没有被执行。
FALSE
您需要编写此函数的代码,以便在找不到您要查找的内容时返回。
所以
if (array_search($soca, $user_socs) !== false) {
// then I found something
// not sure what but its defintely not
// returning a failed to find situation
} else {
// I did not find anything
}
Run Code Online (Sandbox Code Playgroud)
请注意,使用 the!==
和 NOT !=
this 明确适用于函数可以返回可能等于 false 但实际上并非 false 的实际数据的情况,即它可能返回第 0 个出现的情况,它是一个有效的出现,如果以下情况可能会与 false 混淆你只是我们==
。