在PHP中克服针干草堆混乱

P M*_*P M 12 php language-design

在PHP中克服针干草堆混淆最实用的方法是什么?

这里$ needle是第一个参数

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
Run Code Online (Sandbox Code Playgroud)

这里$ needle是第二个参数

string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
Run Code Online (Sandbox Code Playgroud)

Kin*_*xit 8

如果您将此视为修复操作的预修复表示,则可能有意义.

is "bat" in array ("cat", "rat", "bat", "fat")
is $needle in_array $haystack
in_array($needle, $haystack)


does "supercalifragistic" string contain string "percal"
does $haystack strstr $needle
strstr($haystack, $needle)
Run Code Online (Sandbox Code Playgroud)

  • 但是为什么``haystack strstr $ needle`这句话更合乎逻辑呢?`$ needle strstr $ haystack`? (2认同)

Ric*_*eed 5

我为包含needle haystack 参数的所有php 命令制作了一个备忘单。

字符串函数是大海捞针/针:

          strpos $haystack, $needle
         stripos $haystack, $needle
          strstr $haystack, $needle
          strchr $haystack, $needle
         stristr $haystack, $needle
         strrchr $haystack, $needle
        strripos $haystack, $needle
         strrpos $haystack, $needle
    substr_count $haystack, $needle

strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int
stripos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int
strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string
(same as strstr) strchr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string
stristr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string
strrchr ( string $haystack , mixed $needle ) : string
strripos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int
strrpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int
substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] ) : int
Run Code Online (Sandbox Code Playgroud)

数组函数是needle/haystack(array_filter除外):

    array_search $needle, $haystack
        in_array $needle, $haystack

in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
array_search ( mixed $needle  , array $haystack  [, bool $strict  ] )
Run Code Online (Sandbox Code Playgroud)

array_filter ( array $array [, callable $callback [, int $flag = 0 ]] ) : array


Gig*_*egs -1

我认为这并不重要。Linux bash 也是如此。例如,tar 使用参数存档文件,但 ln 使用参数目标链接名。但我的例子不是编程语言,所以这里有另一个解释:世界上第一个计数或编号是什么?对于你所需要的,它总是 2 个参数。我的 tar 和 ln 示例也是如此。