upiz Posted March 2, 2011 Report Share Posted March 2, 2011 Ir vajadzīgs lai noteiktā laikā rādītu savu tekstu... kā lai izvada arraya otro elementu? $laiks = '9.30'; $tim = array( '8.00' => 'pirmais', '9.00' => 'otrais', '10.00' => 'tresais' ); $i=0; foreach ($tim as $lks => $not) { if ($laiks>=$lks) { $i++; } } //izvada 2, bet kaa lai to sasaista ar $tim arrayu? echo $i; Quote Link to comment Share on other sites More sharing options...
marcis Posted March 2, 2011 Report Share Posted March 2, 2011 $output = ''; foreach($tim as $lks => $not){ if($laiks < $lks) break; $output = $not; } echo $output; Quote Link to comment Share on other sites More sharing options...
upiz Posted March 2, 2011 Author Report Share Posted March 2, 2011 ahh, cik vienkārši, paldies! Quote Link to comment Share on other sites More sharing options...
Rincewind Posted March 2, 2011 Report Share Posted March 2, 2011 Man vienam tas šķiet neefektīvs vaids? Paņemt tekošo stundu kā int un no array ņemt pēc indeksa, kas tur ko ciklot? Quote Link to comment Share on other sites More sharing options...
marcis Posted March 2, 2011 Report Share Posted March 2, 2011 Minūtes konkrētajā gadījumā izskatās liekas, attiecīgi varētu palikt tikai pie stundu čekošanas. No performances viedokļa - cikls nepatērēs praktiski necik laika. Protams, ja gribi, vari droši sarakstīt pilnu masīvu - 24 elementi, izpildes laiks būs ~ tas pats. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.