deserty Posted November 29, 2011 Report Posted November 29, 2011 Am un array de genul$two=array("2", "3", "2", "1", "3");Cu ce functie pot calcula de cate ori se afla valoare 2 in array ? Quote
Zatarra Posted November 29, 2011 Report Posted November 29, 2011 (edited) Am un array de genul$two=array("2", "3", "2", "1", "3");Cu ce functie pot calcula de cate ori se afla valoare 2 in array ?Nu stiu sigur daca chiar exista vre-o functie dar poti crea tu una.function getNumber($valoare,$sir){ $contor=0; for ($i=0;$i<count($sir);$i++) { if ($sir[$i]==$valoare) {$contor++;} } return $contor;}Nu am probat dar trebuie sa mearga.Ca sa apelezi folosesti getNumber("gica",$array); Edited November 29, 2011 by Zatarra Quote
BogdanNBV Posted November 29, 2011 Report Posted November 29, 2011 (edited) e ~ corect cum ti-a facut Zatarra, dar cu o mica modificare:asa este corect 100%function getNumber($valoare,$sir){ $contor=0; for ($i=0;$i<count($sir);$i++) { if ($sir[$i]==$valoare) {$contor++;} } return $contor;} Edited November 29, 2011 by BogdanNBV Quote
Zatarra Posted November 29, 2011 Report Posted November 29, 2011 Da, scuze, ai dreptate. Am facut aseara un script unde am folosit <= si mi-a ramas de atunci in minte. Ai dreptate, e mai mic strict deoarece incepe de la 0.Ms de precizare. Quote
devacanta Posted November 29, 2011 Report Posted November 29, 2011 array_count_values($array) 1 Quote
Zatarra Posted November 29, 2011 Report Posted November 29, 2011 array_count_values($array)Multam fain, mai am si eu nevoie cateodata.+rep Quote