note 76902 added to language.control-structures

From: Date: Sat, 04 Aug 2007 13:48:51 +0000
Subject: note 76902 added to language.control-structures
Groups: php.notes 
Request: Send a blank email to php-notes+get-129174@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: 66.207.199.35 Probable Submitter: 67.55.16.180 ---- Manual Page -- http://www.php.net/manual/en/language.control-structures.php Edit -- https://master.php.net/note/edit/76902 Del: integrated -- https://master.php.net/note/delete/76902/integrated Del: useless -- https://master.php.net/note/delete/76902/useless Del: bad code -- https://master.php.net/note/delete/76902/bad+code Del: spam -- https://master.php.net/note/delete/76902/spam Del: non-english -- https://master.php.net/note/delete/76902/non-english Del: in docs -- https://master.php.net/note/delete/76902/in+docs Del: other reasons-- https://master.php.net/note/delete/76902 Reject -- https://master.php.net/note/reject/76902 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129174) next »