I want to get the same value from two arrays. Example:
a[] = array(a,b,c,d,e,f,g,h);
b[] = array(c,d,o,l,p,i,u,y);
I want c[]=c,d;
The array_diff() function compares the values of two (or more) arrays, and returns the differences. This function compares the values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in array2 or array3, etc.
The array_keys() is a built-in function in PHP and is used to return either all the keys of and array or the subset of the keys. Parameters: The function takes three parameters out of which one is mandatory and other two are optional.
In order to check whether every value of your records/array is equal to each other or not, you can use this function. allEqual() function returns true if the all records of a collection are equal and false otherwise. let's look at the syntax… const allEqual = arr => arr.
Note: Only the difference in using [] or array() is with the version of PHP you are using. In PHP 5.4 you can also use the short array syntax, which replaces array() with [].
<?php
$arr = array_intersect(array('a', 'b', 'c', 'd'),
array('c', 'd', 'e', 'f'));
print_r(array_values($arr));
Use array_intersect($a,$b)
-- Ohh many guys answered before i typed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With