Hello, I have cafeid=(1,2,3,4,5,6,7) and checkid= (1,3,5)
How can I show the output only (2,4,6,7)?
Thank you for your answers.
Hello, I have cafeid=(1,2,3,4,5,6,7) and checkid= (1,3,5)
How can I show the output only (2,4,6,7)?
Thank you for your answers.
By using
Example:
$cafeid = array(1,2,3,4,5,6,7);
$checkid = array(1,3,5);
print_r( array_diff($cafeid, $checkid) );
will give:
Array
(
[1] => 2
[3] => 4
[5] => 6
[6] => 7
)
You can use the array_diff
function to return the values that are present in the first array, and not in the second one.
As an example, in your situation, this portion of code :
$cafeid = array(1,2,3,4,5,6,7);
$checkid = array(1,3,5);
var_dump(array_diff($cafeid, $checkid));
will get you this kind of output :
array
1 => int 2
3 => int 4
5 => int 6
6 => int 7
As an advice : there are a lot of useful function that allow one to manipulate arrays and work with them ; you should take a quick look at the list of those functions : Array Functions.
I'm pretty sure this'll be useful one day or another ;-)