Hennikenno Posted June 27, 2009 Report Posted June 27, 2009 Sveiki. Man ir viens kods, kur lietotājs var ar radio inputiem izvēlēties vienu no trīs iespējām. Pēctam nākamajai lapa, kas saņem izvēli ar $_POST šī izvēle ir jāsalīdzina ar vienu no trim iespējām. Ja ar nevienu no iespējām nesakrtīt, tad izmet erroru. Man bija kas līdzīgs šim, bet man vislaik meta erroru: $type = $_POST['type']; if($type != "str1" || $type != "str2" || $type != "str3") { stderr("Error", "$type - invalid"); } Neatkarīgi no tā, vai $type bija kāds no iespējamajiem variantiem (str1, str2 vai str3), errors tika izmests tikuntā... Kas ir nepareizi? ps. Neesmu jau gluži pro un vienkārši meklēju palīdzību, lai šis īsais kods nobūtu jāpārvērš garākā... Quote
v3rb0 Posted June 27, 2009 Report Posted June 27, 2009 tips nav str1 vai tips nav str2 vai tips nav str3 jebšu tips nav str1 un tips nav str2 un tips nav str3 Quote
Hennikenno Posted June 27, 2009 Author Report Posted June 27, 2009 Ok, aizgāja, paldies (sapratu arī, kāpēc pirmstam negaja) ;) Quote
ohmygod Posted June 27, 2009 Report Posted June 27, 2009 nebūtu ērtāk izmantot switch? switch($type){ case '1' : daram kko; break; case '2' : daram kko; break; case '3' : daram kko; break; case ($type > 3) : daram kko; break; default: varbūt kaut ko daram; break; } Quote
bubu Posted June 27, 2009 Report Posted June 27, 2009 case ($type > 3) tāda sintakse ir invalīda. Quote
ohmygod Posted June 27, 2009 Report Posted June 27, 2009 Kopš kura laika? Viņa darbojas un ir arī php.net piemēros. Quote
cucumber Posted June 27, 2009 Report Posted June 27, 2009 php piemeros neatradu, bet man uz PHP Version 5.2.6 strada! Quote
v3rb0 Posted June 27, 2009 Report Posted June 27, 2009 php.net/switch The case expression may be any expression that evaluates to a simple type no tā izriet, ka valīdi ir rakstīt kaut vai switch(true) { case $foo==$bar: // .. break; case $a=$dbResult->fetch(): // .. break; case new Foo() ? true : false : // .. break; } Quote
Hennikenno Posted June 27, 2009 Author Report Posted June 27, 2009 Es jau savu panācu, man citus variantus itkā nevajag :D Quote
bubu Posted June 27, 2009 Report Posted June 27, 2009 ok, tādu brīnumu nezināju. Mūžu dzīvo, mūžu mācies :) Quote
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.