Assuming that you have three arrays which might contain different values as follows.:
$arr1 = array('1', '5', '10');
$arr2 = array('1', '3', '10');
$arr3 = array('1', '6', '10');
How would you strip out what's different and get it as follows?:
$arr1 = array('1', '10');
$arr2 = array('1', '10');
$arr3 = array('1', '10');
I meant I wanted to get it as follows.:
$result = array('1', '10');
The + operator in PHP when applied to arrays does the job of array UNION. $arr += array $arr1; effectively finds the union of $arr and $arr1 and assigns the result to $arr .
An array is a data structure that stores one or more similar type of values in a single value. For example if you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100 length.
=> is the separator for associative arrays. In the context of that foreach loop, it assigns the key of the array to $user and the value to $pass .
To create an array, you use the array() construct: $myArray = array( values ); To create an indexed array, just list the array values inside the parentheses, separated by commas.
Use array_intersect
function:
<?php
$arr1 = array('1', '5', '10');
$arr2 = array('1', '3', '10');
$arr3 = array('1', '6', '10');
$result = array_intersect($arr1, $arr2, $arr3);
print_r($result);
//now assign it back:
$arr1 = $result;
$arr2 = $result;
$arr3 = $result;
?>
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