d_01 Posted January 24, 2008 Report 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!
andrisp Posted January 24, 2008 Report Posted January 24, 2008 Vienīgais veids ko zinu un lietoju (diemžēl ar masīviem): if (in_array($value, array(1,2,3))) {}
Toms Posted January 24, 2008 Report 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; }
Delfins Posted January 24, 2008 Report Posted January 24, 2008 Kas tev pret masīviem !? Pīpēt vajag mazāk. PS: var izmantot strpos() un t.t.
Aleksejs Posted January 24, 2008 Report Posted January 24, 2008 switch($a){ case 1,2,3,4,5: do_something; break; }
andrisp Posted January 24, 2008 Report Posted January 24, 2008 (edited) Toms, Aleksejs, kas tie par "risinājumiem" ? Edited January 24, 2008 by andrisp
d_01 Posted January 24, 2008 Author Report 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!
blackhalt Posted January 24, 2008 Report Posted January 24, 2008 Man gan tur tas stristr nelīmējas. Tad labak to in_array
andrisp Posted January 24, 2008 Report 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
Recommended Posts