goma smile Posted December 16, 2013 Report Share Posted December 16, 2013 Iedomājietes ir Id, Cena_no, Cena_līdz, Atlaide(%) Kā izveidot lai pie post pārbauda vai ir diapazoni kas vienu otru netraucētu 1 - 5 5-6 Lai nevarētu radīt 1-5 2-6 Quote Link to comment Share on other sites More sharing options...
php newbie Posted December 16, 2013 Report Share Posted December 16, 2013 tāds primitīvs variants kad katru ar katru salidzina. atnaks codez un pa 3 min. uzrakstīs normālu algoritmu foreach ( $ranges as $key1 => $range1) { foreach ( $ranges as $key2 => $range2) { if ($key1 != $key2 && $range1['cena_no'] <= $range2['cena_lidz'] && $range1['cena_lidz'] >= $range2['cena_no'] { //error } } } Quote Link to comment Share on other sites More sharing options...
daGrevis Posted December 16, 2013 Report Share Posted December 16, 2013 > atnaks codez un pa 3 min. uzrakstīs normālu algoritmu Haha! Quote Link to comment Share on other sites More sharing options...
aaxc Posted December 16, 2013 Report Share Posted December 16, 2013 Laikam iebraucu ko tev vajag: <?php $range1 = range( 1, 5 ); $range2 = range( 5, 6 ); if ( count( array_intersect( $range1, $range2 ) ) == 0 ) echo 'Clean'; else echo 'Wrong'; ?> Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted December 16, 2013 Report Share Posted December 16, 2013 sakārto intervālus pēc sākuma vērtības, tad iterē cauri sakārtotai listei un skaties vai nākošā intervāla sākums ir pirms tekošā intervāla beigām. Quote Link to comment Share on other sites More sharing options...
aaxc Posted December 16, 2013 Report Share Posted December 16, 2013 Jā, bet tad loģika ir nepareiza jautājumā, jo, ja abos diapazonos ir 5, tad tie diapazoni jebkurā gadījumā pārklājas. Ja vajag atļaut, ka pēdējais un / vai pirmais pārklājas, tad var vienkārši pārbaudīt, vai sakrīt viens vai mazāk ciparu: <?php $range1 = range( 1, 5 ); $range2 = range( 5, 6 ); if ( count( array_intersect( $range1, $range2 ) ) <= 1 ) echo 'Clean'; else echo 'Wrong'; ?> Quote Link to comment Share on other sites More sharing options...
php newbie Posted December 16, 2013 Report Share Posted December 16, 2013 labākais būtu v3rb0 variants. vēl var izmantot manu shitkodu, bet array_intersect neder 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.