php - How to get common minimum value in two arrays -


i have function checks on 2 arrays , returns common minimum value in both arrays. returns correct answer when both arrays have equal number of elements. other other bigger not return correct one. how overcome this?

<?php     $a = array(0);     $b= array(1,0);     $n = sizeof($a);     $m = sizeof($b);     sort($a);     sort($b);     $i = 0;     ($k = 0; $k < $n; $k++) {         if ($i < $m - 1 , $b[$i] < $a[$k])             $i += 1;         if ($a[$k] == $b[$i])             echo $a[$k];     }     echo "end";  ?> 

thanks

a way simpler way take minimum value of intersection of arrays :

$array = array (5,6,7,8,9); $array2 = array (9,7,5,3,4,1);  $min = min(array_intersect($array, $array2)); echo $min; // 5 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -