map_month() - Predefined Drupal Function
To get the month name using the numbers of the month.
$val = map_month(3);
echo $val;
Output:
Mar
To get the month name using the numbers of the month.
$val = map_month(3);
echo $val;
Output:
Mar
Array ( [#value] => Array ( [day] => 24 //(current day) [month] => 2 //(current month) [year] => 2012 //(current year) ) [#tree] => 1 [month] => Array //(Months List) ( [#type] => select [#value] => 2 [#attributes] => [#options] => Array ( [1] => Jan [2] => Feb [3] => Mar [4] => Apr [5] => May [6] => Jun [7] => Jul [8] => Aug [9] => Sep [10] => Oct [11] => Nov [12] => Dec ) ) [day] => Array //(Days List) ( [#type] => select [#value] => 24 [#attributes] => [#options] => Array ( [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 ) ) [year] => Array //(Year List from 1900 to 2050) ( [#type] => select [#value] => 2012 [#attributes] => [#options] => Array ( [1900] => 1900 [1901] => 1901 [1902] => 1902 [1903] => 1903 [1904] => 1904 [1905] => 1905 [1906] => 1906 [1907] => 1907 [1908] => 1908 [1909] => 1909 [1910] => 1910 [1911] => 1911 [1912] => 1912 [1913] => 1913 [1914] => 1914 [1915] => 1915 [1916] => 1916 [1917] => 1917 [1918] => 1918 [1919] => 1919 [1920] => 1920 [1921] => 1921 [1922] => 1922 [1923] => 1923 [1924] => 1924 [1925] => 1925 [1926] => 1926 [1927] => 1927 [1928] => 1928 [1929] => 1929 [1930] => 1930 [1931] => 1931 [1932] => 1932 [1933] => 1933 [1934] => 1934 [1935] => 1935 [1936] => 1936 [1937] => 1937 [1938] => 1938 [1939] => 1939 [1940] => 1940 [1941] => 1941 [1942] => 1942 [1943] => 1943 [1944] => 1944 [1945] => 1945 [1946] => 1946 [1947] => 1947 [1948] => 1948 [1949] => 1949 [1950] => 1950 [1951] => 1951 [1952] => 1952 [1953] => 1953 [1954] => 1954 [1955] => 1955 [1956] => 1956 [1957] => 1957 [1958] => 1958 [1959] => 1959 [1960] => 1960 [1961] => 1961 [1962] => 1962 [1963] => 1963 [1964] => 1964 [1965] => 1965 [1966] => 1966 [1967] => 1967 [1968] => 1968 [1969] => 1969 [1970] => 1970 [1971] => 1971 [1972] => 1972 [1973] => 1973 [1974] => 1974 [1975] => 1975 [1976] => 1976 [1977] => 1977 [1978] => 1978 [1979] => 1979 [1980] => 1980 [1981] => 1981 [1982] => 1982 [1983] => 1983 [1984] => 1984 [1985] => 1985 [1986] => 1986 [1987] => 1987 [1988] => 1988 [1989] => 1989 [1990] => 1990 [1991] => 1991 [1992] => 1992 [1993] => 1993 [1994] => 1994 [1995] => 1995 [1996] => 1996 [1997] => 1997 [1998] => 1998 [1999] => 1999 [2000] => 2000 [2001] => 2001 [2002] => 2002 [2003] => 2003 [2004] => 2004 [2005] => 2005 [2006] => 2006 [2007] => 2007 [2008] => 2008 [2009] => 2009 [2010] => 2010 [2011] => 2011 [2012] => 2012 [2013] => 2013 [2014] => 2014 [2015] => 2015 [2016] => 2016 [2017] => 2017 [2018] => 2018 [2019] => 2019 [2020] => 2020 [2021] => 2021 [2022] => 2022 [2023] => 2023 [2024] => 2024 [2025] => 2025 [2026] => 2026 [2027] => 2027 [2028] => 2028 [2029] => 2029 [2030] => 2030 [2031] => 2031 [2032] => 2032 [2033] => 2033 [2034] => 2034 [2035] => 2035 [2036] => 2036 [2037] => 2037 [2038] => 2038 [2039] => 2039 [2040] => 2040 [2041] => 2041 [2042] => 2042 [2043] => 2043 [2044] => 2044 [2045] => 2045 [2046] => 2046 [2047] => 2047 [2048] => 2048 [2049] => 2049 [2050] => 2050 ) ) )
class Bicycle
{
var $attribute1;
var $attribute2;
function method1()
{
// Code here
return $something;
}
function method2()
{
// Code here
}
}
$myBicycle = new Bicycle();
$myBicycle2 = new Bicycle();
$myBicycle3 = new Bicycle();
$myBicycle4 = new Bicycle();
->
(sometimes called the arrow operator; although it’s not really an operator). When you are accessing a variable in PHP, the part of code after the $
is known as the namespace.
When you are accessing attributes and methods that are members of an
object, you need to extend that namespace to include the name of your
object. To do this, you reference attributes and methods like so:// Assigning Value to Attributes
$myBicycle->attribute1 = 'Red';
$myBicycle->attribute2 = 'Hero';
// Calling Methods
$returned = $myBicycle->method1();
$myBicycle->method2();
->
separator. Since we can have objects within objects, we can also extend this further. For example, if our $myBicycle
object was a member of another object called $anotherObject
, we could reference the members of $myBicycle
like so:// Assigning Value to Attributes
$anotherObject->myBicycle->attribute1 = 'Red';
$anotherObject->myBicycle->attribute2 = 'Hero';
// Methods
$returned = $anotherObject->myBicycle->method1();
$anotherObject->myBicycle->method2();
$
appears only once before the namespace; this is because a variable name in PHP can only ever have a single dollar sign. If we were to place another $
anywhere in our namespace, we’d be telling PHP we were using variable variables. I don’t really want to go too far off topic here, so have a look at the PHP documentation for more information about variable variables.$this
Pseudo-Variable$this
pseudo-variable:class Bicycle
{
var $attribute1;
function method1()
{
return $this->attribute1;
}
}
$this
can also be thought of as ‘my own’ or ‘current object’. In our example, we’re returning the value of $attribute1
within the ‘current object’.<?php class RoadBike extendsBicycle {
private $num_spoke; private $handlebars;}
<?php class A { function A() { echo "I am the constructor of A.<br />\n"; } function B() { echo "I am a regular function named B in class A.<br />\n"; echo "I am not a constructor in A.<br />\n"; } } class B extends A { } // This will call B() as a constructor $b = new B; ?>