hoho Posted September 29, 2006 Report Share Posted September 29, 2006 vai php ir kaada iebuuveeta funkcija, kas atrod masiivaa unikaalus elementus (kas atkartojas tikai vienu reizi)?! Link to comment Share on other sites More sharing options...
Vebers Posted September 29, 2006 Report Share Posted September 29, 2006 (edited) Nē, bet ir funkcija, kura izdzēš no masīva dublētos ierakstus. P.S. http://php.net/array_unique Edited September 29, 2006 by MakaTaNaw Link to comment Share on other sites More sharing options...
Stopp Posted September 29, 2006 Report Share Posted September 29, 2006 (edited) iebūvēta laikam nav. function checharray($arr) { $newarr=array(); foreach ($arr as $key => $value) { if (!in_array($value, $newarr)) $newarr[]=$value; } } kaut kam tādam vajadzētu derēt. Edited September 29, 2006 by Stopp Link to comment Share on other sites More sharing options...
hoho Posted September 29, 2006 Author Report Share Posted September 29, 2006 nee, man bija mazliet cita doma piemeerem ja masiiva elementi 3 3 4 5 4 5 6 tad taa funkcija atgriez 3 4 5 6 bet vajag tikai 6 Link to comment Share on other sites More sharing options...
Delfins Posted September 29, 2006 Report Share Posted September 29, 2006 Nu un kur problēma sastādīt vienkāršu algoritmu? foreach ( $arr AS $v) { @$idxArr[$v] += 1; } foreach ($idxArr AS $k => $v ) { if ($v > 1) unset($idxArr[$k]); } return array_keys($idxArr); Link to comment Share on other sites More sharing options...
hoho Posted September 29, 2006 Author Report Share Posted September 29, 2006 paldies! ;) Link to comment Share on other sites More sharing options...
bubu Posted September 29, 2006 Report Share Posted September 29, 2006 Delfin, fui cik nesmuku kodu tu uzrakstīji ;) function isOne($x) { return $x==1; } $unique = array_keys(array_filter(array_count_values($arr), "isOne")); Link to comment Share on other sites More sharing options...
KAC Posted September 30, 2006 Report Share Posted September 30, 2006 varbut nesmukaaks, bet vienkaarshaaks un lasaamaaks Link to comment Share on other sites More sharing options...
bubu Posted September 30, 2006 Report Share Posted September 30, 2006 ..un iespējams lēnāks. php kods vienmēr būs lēnāks, nekā ekvivalentas darbības iebūvētās funkcijas (jo rakstītas iekš C), un īpaši uz lieliem masīviem. Cikla ķermeni vienmēr ieteicams aizdzīt cik vien "zemu" iespējams, tb tuvāk C kodam, ja tiek domāts par optimizāciju. Link to comment Share on other sites More sharing options...
Recommended Posts