Repeated data


I would like you to give me a hand with this since I can not find the turn This would be my code, The variable $a and $b I bring from the controller and the values are:

       @for ($i = 0; $i < count($b); $i++)
           @foreach ($a as $c)
                @if ($b[$i] == $c)
                    <option>{{ $c }}</option>

With this condition it brings me a select 1,4,8 and if I put this condition !== brings me from 2 to 10 after 1 to 10 without 4 and finally from 1 to 10 without 8. How do I have to make it to bring me



I do not know if it's easy or difficult but I do not realize how I have to do.

asked by Segurida IT 02.11.2017 в 05:33

2 answers


You can do like this:

$a = [1,2,3,4,5,6,7,8,9,10];
$b = [1,4,8];
$resultado = array_diff($a, $b)

@foreach ($resultado as $value):

you send the variable $resultado

Source: array_diff ()

answered by 02.11.2017 / 06:09

What you want to obtain is the difference between two arrangements, for this you can use the underscore library to do it in a simpler way and with fewer code lines, since this library applies functional programming (without variable states).


__::difference($a, $b);



Library reference in php link

This same library exists for javascript link

answered by 02.11.2017 в 05:48