3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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]; } }
Output for 7.1.0
Array ( [0] => 134567 [1] => dogs [2] => food [3] => EEUU ) Array ( [0] => 134567 [1] => dogs [2] => toys [3] => EEUU ) Differences: Warning: A non-numeric value encountered in /in/RFFE8 on line 36
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.14
Array ( [0] => 134567 [1] => dogs [2] => food [3] => EEUU ) Array ( [0] => 134567 [1] => dogs [2] => toys [3] => EEUU ) Differences: