i store numbers in array in following way:
467:0
467 number , 0 number of occurances.
doing grab bunch of numbers db , numbers appear more once, if incredement number of occurances.
$numbercount = explode(':', $this->_presentationarr); if(in_array($numberprefix . ':' . preg_match('/^\d+$/', $numbercount[1]), $this->_presentationarr)) { $pos = array_search($numberprefix . ':' . preg_match('/^\d+$/', $numbercount[1]), $this->_presentationarr); $tmparr = explode(':', $this->_presentationarr[$pos]); $tmparr[1]++; # not work }
$tmparr[1] number needs incredementet each match. ideas?
i think you're overcomplicating things. php arrays bit different arrays in c, behave more map. means can insert keys without worrying whether previous key exists. , means can create frequence map , quickly, this:
$occurrencearray = array() // next line pseudocode while ($fetched = fetchnumber()) { $occurrencearray[$fetched]++; } // once numbers loaded can iterate on occurrence map foreach ($occurrencearray $key => $value) { printf("number %d occurs %d times",$key,$value); // or of course reconvert "key:value" strings storing }
Comments
Post a Comment