d_01 Posted January 24, 2008 Report Share Posted January 24, 2008 Vai kāds zin veidu kā var izveidot if funkciju ar vairākiem parametriem. piemērā būs skaidrāk ko es vēlos: $a=1; if($a == 1 OR $a == 2 OR $a == 3){ echo 111; } izveidot īsāk lai būtu kkā tā: if($a in (1,2,3)){ echo 111; } p.s. bez masīviem Paldies! Link to comment Share on other sites More sharing options...
andrisp Posted January 24, 2008 Report Share Posted January 24, 2008 Vienīgais veids ko zinu un lietoju (diemžēl ar masīviem): if (in_array($value, array(1,2,3))) {} Link to comment Share on other sites More sharing options...
Toms Posted January 24, 2008 Report Share Posted January 24, 2008 switch ($a) { case 0: case 1: case 2: echo "$a IN(0,1,2)"; break; case 5: echo "$a IN (5)"; break; default: echo "neatbilda nevienam"; break; } Link to comment Share on other sites More sharing options...
Delfins Posted January 24, 2008 Report Share Posted January 24, 2008 Kas tev pret masīviem !? Pīpēt vajag mazāk. PS: var izmantot strpos() un t.t. Link to comment Share on other sites More sharing options...
Aleksejs Posted January 24, 2008 Report Share Posted January 24, 2008 switch($a){ case 1,2,3,4,5: do_something; break; } Link to comment Share on other sites More sharing options...
andrisp Posted January 24, 2008 Report Share Posted January 24, 2008 (edited) Toms, Aleksejs, kas tie par "risinājumiem" ? Edited January 24, 2008 by andrisp Link to comment Share on other sites More sharing options...
d_01 Posted January 24, 2008 Author Report Share Posted January 24, 2008 Paldies par risinājumiem! nebiju gaidījis ka tik ātri kāds atbildēs! :) CASE derēs pats tikko atradu šādu variantu tas tikai string tipa mainīgajiem (arī norm strādā). $a="2"; if (stristr("123",$a)){ echo 111; } vairāk neko pagaidām nevajag! Paldies visiem kuri atbildēja! Link to comment Share on other sites More sharing options...
Toms Posted January 24, 2008 Report Share Posted January 24, 2008 andrisp, pavisam normāli. Noder dažreiz. Link to comment Share on other sites More sharing options...
blackhalt Posted January 24, 2008 Report Share Posted January 24, 2008 Man gan tur tas stristr nelīmējas. Tad labak to in_array Link to comment Share on other sites More sharing options...
andrisp Posted January 24, 2008 Report Share Posted January 24, 2008 (edited) Toms, iebraucu jā. Vienkārši parasti switch'us neizmantoju praktiski nemaz, tāpēc nesapratu. :) At tas stristr variants gan nav labs - laidīs cauri arī 12, 23 un 123. Edited January 24, 2008 by andrisp Link to comment Share on other sites More sharing options...
Recommended Posts