I am looking for a way to validate one array obtained via a form.
$arr = [13, 64];
The array is composed of 2 integers and I need to check that these integers are between 0 ad 1000, but also the 2nd integer is greater than the first AND the difference cannot exceed 100.
The only only constraint I could put was the one validating the number with a know pattern :
'constraints' => new AssertCollection([
'fields' => [
0 => new AssertRange([
'min' => 0,
'max' => 1000,
]),
1 => new AssertRange([
'min' => 0,
'max' => 1000,
]),
]
]),
What is missing in my validation:
$arr = [13, 64]; => should be correct
$arr = [140, 64]; => not correct, $arr[0] > $arr[1]
$arr = [13, 340]; => not correct, ($arr[1] - $arr[0]) > 100
I couldnt find in the symfony doc how to validate array fields among each others, and don’t event know if there is a way to.
If anyone has a tip, you’re welcome 🙂
thank you and cheers !