How to organize matrix

Asked

Viewed 74 times

-1

a comparison is being made:

this way

$result3 = array_diff($fetchForm, $items['form_id']);
print_r($result3);

    Array
    (
        [0] => 1
        [2] => 3
    )

$result2 = array_diff($items['form_id'], $fetchForm);
print_r($result2);

    Array
    (
        [1] => 4
    )

so that way

Array
(
    [0] => 1
    [1] => 3
)

Array
(
    [0] => 4
)
  • 2

    I don’t understand the question. And these arrays that you showed, are the diff input?

  • these arrays are the exits

  • 2

    What do you mean "the" exits? array_diff returns one array. And what would be the entries then?

  • 1

    It seems to me that we missed the clear question. Edit there and try to explain better to try to help.

  • lost yes... but this and another part more the front Kela part I could not solve for now I am developing this one then you will return there you will publish it to see if you can give me a hand

  • then are two inputs so 2 array... actually and 1 input just there matches the database there separates into 2 array

  • You have 2 array_diff?

  • 1

    yes... I edited it... the diff is the opposite of the other

  • 1

    thanks staff @Papacharlie solved :D

Show 4 more comments

1 answer

2


Array-diff, returns an array containing all array1 entries that are not present in any of the other arrays.

Array-diff will return to KEY and VALUE, for this reason you do not receive an array with ordered indices.

$array1 = array("verde", "vermelho", "azul", "amarelo");
$array2 = array("verde", "vermelho");
$result = array_diff($array1, $array2);

output: array( 2 => 'azul' , 3 => 'amarelo' )


To redo your array in order, you can use array_values

$result = array_values( $result );
print_r($result);

output: array( 0 => 'azul' , 1 => 'amarelo' )

  • 3

    worked perfect, thank you!!!

Browser other questions tagged

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