[ create a new paste ] login | about

Link: http://codepad.org/ybfUgJRJ    [ raw code | output | fork ]

PHP, pasted on Feb 21:
<?php




function getFirstRepetition($array) {
	$prev = array();
	foreach($array as $value) {

	if (in_array($value, $prev)) {
    		return $value;
 	}

        $prev[] = $value;

 
   
	}
        return FALSE;
}

var_dump(getFirstRepetition(array(6, 12, 14, 2, 12)));


Output:
1
int(12)


Create a new paste based on this one


Comments: