This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
这是什么 => 符号在 PHP 中调用。我知道它可以解释为等号直角括号。| 可以称为 Pipe 或 OR。但我的教授要求另一个术语调用 => 符号。它用于为数组类中的键赋值。有谁知道这叫什么?
我试图为价格制作正则表达式或空.我有价格部分(荷兰语使用逗号而不是点数)实际上有效
/^\d+(,\d{1,2})?$/
Run Code Online (Sandbox Code Playgroud)
上面的正则表达式在值21,99上验证了ok
现在我尝试添加空部分,以便字段可以......只是空^ $
/(^$|^\d+(,\d{1,2})?$)/
Run Code Online (Sandbox Code Playgroud)
但是当我改变正则表达式时,Laravel开始抱怨:"方法[验证^\d +(,\ d {1,2})?$)/]不存在."
工作正常:
$rules = [
'price' => 'regex:/^\d+(,\d{1,2})?$/'
];
Run Code Online (Sandbox Code Playgroud)
Laravel说没有......:
$rules = [
'price' => 'regex:/(^$|^\d+(,\d{1,2})?$)/'
];
Run Code Online (Sandbox Code Playgroud)
Kenken9990回答 - Laravel不再破坏,但空值仍然是错误的:
$rules = [
'price' => 'regex:/^(\d+(,\d{1,2})?)?$/'
];
Run Code Online (Sandbox Code Playgroud)