@ 2014-05-18T21:50:22Z <?php
$ar_val="134567,dogs,food,EEUU";
$ar_url="134567,dogs,toys,EEUU";
$arrayVal = explode($ar_val, ',');
$arrayUrl = explode($ar_url, ',');
$maxLength = max(sizeof($arrayVal), sizeof($arrayUrl));
$arrayIdsEqual = array();
$arrayIdsDifferent = array();
print_r($arrayVal);
print_r($arrayUrl);
for ($i = 0; $i < $maxLength; $i++) {
if (isset($arrayVal[$i]) && isset($arrayUrl[$i])) {
if ($arrayVal[$i] == $arrayUrl[$i]) {
$arrayIdsEqual[] = $i;
}
else {
$arrayIdsDifferent[] = $i;
}
}
else {
//you arrive here if you have 2 arrays that don't have the same size / sme number of variables
}
}
//assuming your 2 arrays ALWAYS have the same size, you can use the following logic
if (empty($arrayIdsDifferent)) {
echo '2 arrays are the same';
}
else {
echo 'Differences: ';
foreach ($arrayIdsDifferent as $indexDifferent => $currentIdDifferent) {
$output = 'difference ' . $indexDifferent + 1 . ': ';
$output .= 'val = ' . $arrayVal[$currentIdDifferent];
$output .= 'url = ' . $arrayUrl[$currentIdDifferent];
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.38 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.26 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 Array
(
[0] => ,
)
Array
(
[0] => ,
)
2 arrays are the same Output for 7.4.0 - 7.4.25 , 7.4.27 - 7.4.33 Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /in/3RVV3 on line 36
Array
(
[0] => ,
)
Array
(
[0] => ,
)
2 arrays are the same preferences:dark mode live preview
345.88 ms | 402 KiB | 448 Q