Repeated data

2

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:

$a=[1,2,3,4,5,6,7,8,9,10];
$b=[1,4,8]
<select>
       @for ($i = 0; $i < count($b); $i++)
           @foreach ($a as $c)
                @if ($b[$i] == $c)
                    <option>{{ $c }}</option>
                @endif
           @endforeach
    @endfor
</select>

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

  

2,3,5,6,7,9,10.

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
source

2 answers

2

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):
    {{$value}}
@endforeach

you send the variable $resultado

Source: array_diff ()

    
answered by 02.11.2017 / 06:09
source
0

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).

example:

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

result:

 [2,3,5,6,7,9,10]

Library reference in php link

This same library exists for javascript link

    
answered by 02.11.2017 в 05:48