Answer the question
In order to leave comments, you need to log in
Laravel array validation, how to get next element?
Using the star array.* = ''rules'' everything works great, but now there is a need to compare the previous element of the array with the next one, is there such a way? Perhaps using Rule
Answer the question
In order to leave comments, you need to log in
Make a custom rule and apply it to the array field, i.e.:
and inside the rule, check the elements according to the desired algorithm, because you will have access to the entire array.
There is an easy option via array_search . I once used it, but there is no longer a need, arrays are not good to sort through.
$arrayOne = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$arrayTwo = array(0 => 'yellow', 1 => 'blue', 2 => 'green', 3 => 'red');
Примерно будет выглядеть так:
foreach($arrayOne as $array => $value){
$key = array_search($value $arrayTwo); //Первым $key = 2
if($key ...)
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question