note 76901 added to control-structures.switch

From: Date: Sat, 04 Aug 2007 13:46:58 +0000
Subject: note 76901 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-129173@lists.php.net to get a copy of this message
Here's a lazy way of doing an comparison where multiple conditions equal the same result using arrays. if (in_array($year,array(1948, 1960, 1972, 1984, 1996, 2008))) echo "Rat"; elseif (in_array($year,array(1949, 1961, 1973, 1985, 1997, 2009))) echo "Ox"; elseif (in_array($year,array(1950, 1962, 1974, 1986, 1998, 2010))) echo "Tiger"; elseif (in_array($year,array(1951, 1963, 1975, 1987, 1999, 2011))) echo "Rabbit"; elseif (in_array($year,array(1952, 1964, 1976, 1988, 2000, 2012))) echo "Dragon"; elseif (in_array($year,array(1941, 1953, 1965, 1977, 1989, 2001))) echo "Snake"; elseif (in_array($year,array(1942, 1954, 1966, 1978, 1990, 2002))) echo "Horse"; elseif (in_array($year,array(1943, 1955, 1967, 1979, 1991, 2003))) echo "Lamb"; elseif (in_array($year,array(1944, 1956, 1968, 1980, 1992, 2004))) echo "Monkey"; elseif (in_array($year,array(1945, 1957, 1969, 1981, 1993, 2005))) echo "Rooster"; elseif (in_array($year,array(1946, 1958, 1970, 1982, 1994, 2006))) echo "Dog"; elseif (in_array($year,array(1947, 1959, 1971, 1983, 1995, 2007))) echo "Boar"; ---- Server IP: 216.235.15.211 Probable Submitter: 67.55.16.180 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/76901 Del: integrated -- https://master.php.net/note/delete/76901/integrated Del: useless -- https://master.php.net/note/delete/76901/useless Del: bad code -- https://master.php.net/note/delete/76901/bad+code Del: spam -- https://master.php.net/note/delete/76901/spam Del: non-english -- https://master.php.net/note/delete/76901/non-english Del: in docs -- https://master.php.net/note/delete/76901/in+docs Del: other reasons-- https://master.php.net/note/delete/76901 Reject -- https://master.php.net/note/reject/76901 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129173) next »