PHP, Третий комментарий к странице туториала о '
switch' :
--- begin ---
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";
-- end ---
p.s.
ani = [ 'Monkey', 'Rooster', 'Dog', 'Boar', 'Rat', 'Ox', 'Tiger', 'Rabit', 'Dragon', 'Snake', 'Horse', 'Lamb' ]
puts "pending year of the #{ani[ Time.now.year % 12 ]}"
Комментариев нет:
Отправить комментарий