public function findSmallest($links, $type, $string) { $arr = array(); for ($i = 0; $i < sizeof($links['result']['formats']); $i++) { if (strpos($links['result']['formats'][$i]['quality'], $string) !== false && $links['result']['formats'][$i]['type'] !== $type) { array_push($arr, array('index' => $links['result']['formats'][$i])); } } $index = $arr[0]; if (sizeof($arr) > 1) { $smallestSize = GenFun::getSizeFile($arr[0]['index']['url']); for ($i = 1; $i < sizeof($arr); $i++) { $size = GenFun::getSizeFile($arr[$i]['index']['url']); if ($size < $smallestSize) { $index = $arr[$i]; $smallestSize = $size; } } } return $index; }