how to compare two matrices and bring different values?

Asked

Viewed 99 times

1

I’m trying to do the scheme of creating a loop from 1 to 70 for example

at the bank will return

1 10 11 20 39 50 67 69

from 1 to 70 only it will all, will only bring some numbers between 1 and 70 .

I am trying to create a loop using the for from 1 to 70 and compare with the values shown above that returns from the database, I need to show on the screen the values from 1 to 70 that do not have in the database, I mean that it would be possible to do this?

Follows the code:

$aleatorio = rand(1, 70);
echo $aleatorio."<br>";
$recorte = $valor."_".$aleatorio;


$query = mysqli_query($con,"select material_name_crop from qe.etiquetas_recortadas_aoi where material_name_crop = '$recorte' and line = '$pkg' and brand = '$brand'") or die("erro na query");
$rows = mysqli_num_rows($query);
if($rows < 1){
    echo $recorte." - ".$pkg." - ".$brand." S";
}else{
    $pesq = mysqli_query($con,"select material_name_crop from qe.etiquetas_recortadas_aoi where material_name_crop like '%$valor%' and line = '$pkg' and brand = '$brand'") or die("erro na query");
    $total = mysqli_num_rows($pesq);
    echo "Total ".$total."<br><hr>";
    $count = 0;
    while($recorte = mysqli_fetch_array($pesq)){
        $count = $count+1;
        $content = explode("_",$recorte[0]);
        $t = $content[1];

        //print_r($content);
        for($i=0;$i<=70;$i++){

            $j[] = $i;
            //echo $j[$i];
            $result = array_search($j[$i], $content[1]);
            echo $result;

    //      echo array_diff($val)."  -   ";
        }
        echo "<br>".$count." - ".$content[1]."      /       ";

        //print_r($j);


    }
        echo "<br>".$count." - ".$content[1]."      /       ";

        //print_r($j);


    }
    //echo $recorte[0]." - ".$pkg." - ".$brand." N";
}
  • 2

    I would recommend that you already search [Dit] your question and improve the text, mainly using scores. It’s practically illegible and incomprehensible.

  • my doubt is simple I wonder if I can bring different information comparing two arrays

1 answer

0

You can use the function in_array, where she will check if the value is not within the array (in your case, it would be the information coming from the bank).

// Armazena os dados vindo do banco em um array como este
$array_banco = array(1, 4, 7, 8, 2, 90);

for($i = 1; $i <= 70; $i++) {
   // Checa se o valor do for nao esta dentro do array
   if(!in_array($i, $array_banco)) {
        echo $i . ' nao esta dentro do array';
   }
}
  • Would not be for($i = 1; $i <= 70; $i++) { not to return 0(zero)

  • Yes yes, I put it wrong there. I did, thanks for the warning.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.