Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)
$var
parameter can be an array or string. /** * @param reference $var variable to perform the check */ if (Enum::isEmpty($var)) { // do actions }
Check if a value exists in the array. This method is faster in performance than the PHP built in in_array
method. This method accepts the following parameters:
$needle
: mixed, the value to search
$haystack
: array, the array to scan
/** * @param mixed $needle the value to search * @param array $haystack the array to scan */ if (Enum::inArray('apple', ['apple', 'mango', 'banana'])) { echo 'apple exists'; }
/** * @param string $string the input string */ echo Enum::properize("Chris"); echo Enum::properize("David");
/** * @param string $fromTime start date time * @param boolean $human if true returns an approximate human friendly output * - If set to false it will attempt an exact conversion of time intervals. * @param string $toTime end date time - defaults to current system time if not provided * @param string $append the string to append for the converted elapsed time - defaults to ' ago' */ echo 'Human Friendly: ' . Enum::timeElapsed("2011-08-30 03:11:39"); echo 'Raw Conversion: ' . Enum::timeElapsed("2011-08-30 03:11:39", false);
/** * @param double $bytes number of bytes * @param integer $precision the number of decimal places to round off */ echo '<b>Size (KB):</b> ' . Enum::formatBytes(120.32); echo '<b>Size (MB):</b> ' . Enum::formatBytes(28434322.25); echo '<b>Size (GB):</b> ' . Enum::formatBytes(17328347842.25, 3);
/** * @param double $num source number to be converted */ echo '<b>23,289,438 = </b> ' . Enum::numToWords(23289438); echo '<b>380,004 = </b> ' . Enum::numToWords(380004);
from
and to
years. Years till current system date will be generated if to
year is not specified. This is very useful for generating dropdown lists in forms or creating filter inputs in Yii's GridView. Array ( [0] => 2024 [1] => 2023 [2] => 2022 [3] => 2021 [4] => 2020 [5] => 2019 [6] => 2018 [7] => 2017 [8] => 2016 [9] => 2015 [10] => 2014 [11] => 2013 [12] => 2012 [13] => 2011 [14] => 2010 [15] => 2009 [16] => 2008 [17] => 2007 [18] => 2006 [19] => 2005 [20] => 2004 [21] => 2003 [22] => 2002 )
Array ( [1990] => 1990 [1991] => 1991 [1992] => 1992 [1993] => 1993 [1994] => 1994 [1995] => 1995 [1996] => 1996 [1997] => 1997 [1998] => 1998 [1999] => 1999 [2000] => 2000 [2001] => 2001 )
/** * @param integer $from the start year * @param integer $to the end year * @param boolean $keys whether to set the array keys same as the values (defaults to false) * @param boolean $desc whether to sort the years descending (defaults to true) */ print_r(Enum::yearList(2002)); print_r(Enum::yearList(1990, 2001, true, false));
Array ( [1] => January [2] => February [3] => March [4] => April [5] => May [6] => June [7] => July [8] => August [9] => September [10] => October [11] => November [12] => December )
Array ( [1] => APR [2] => MAY [3] => JUN [4] => JUL [5] => AUG [6] => SEP [7] => OCT [8] => NOV [9] => DEC [10] => JAN [11] => FEB [12] => MAR )
/** * @param boolean $abbr whether to return abbreviated month * @param boolean $start the first month to set. Defaults to `1` for `January`. * @param string $case whether 'upper', lower', or null. If null, then * the initcap case will be used. */ print_r(Enum::monthList()); print_r(Enum::monthList(true, 4, 'upper'));
Array ( [1] => Sunday [2] => Monday [3] => Tuesday [4] => Wednesday [5] => Thursday [6] => Friday [7] => Saturday )
Array ( [1] => MON [2] => TUE [3] => WED [4] => THU [5] => FRI [6] => SAT [7] => SUN )
/** * @param boolean $abbr whether to return abbreviated month * @param boolean $start the first day to set. Defaults to `1` for `Sunday`. * @param string $case whether 'upper', lower', or null. If null, then * the initcap case will be used. */ print_r(Enum::dayList()); print_r(Enum::dayList(true, 2, 'upper'));
Array ( [0] => 1 [1] => 7 [2] => 14 [3] => 21 [4] => 28 [5] => 30 )
Array ( [0] => 1 [1] => 5 [2] => 10 [3] => 15 [4] => 20 [5] => 25 [6] => 30 )
/** * @param integer $from the start day, defaults to 1 * @param integer $to the end day, defaults to 31 * @param integer $interval the date interval, defaults to 1. * @param integer $intervalFromZero whether to start incrementing intervals from zero if $from = 1. * @param integer $showLast whether to show the last date (set in $to) even if it does not match interval. */ print_r(Enum::dateList(1, 28, 7)); print_r(Enum::dateList(1, 10));
hour
, min
, sec
, or ms
. This is very useful for generating dropdown lists in forms or creating filter inputs in Yii's GridView. 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
00, 05, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55
/** * @param string $unit the time unit ('hour', 'min', 'sec', 'ms') * @param integer $interval the interval between each time unit list entry. Defaults to 1. * @param integer $from the starting time. Defaults to 0. * @param integer $to the ending time. Defaults to 23 for hour, 59 for min & sec, and 999 for ms. * @param boolean $padZero whether to left pad zero (0) in the time value displayed. Defaults to true */ echo implode(', ', Enum::timeList('hour')); echo implode(', ', Enum::timeList('sec', 5));
Yes
) and false label (default No
). This is very useful for generating dropdown lists in forms or creating filter inputs in Yii's GridView. Array ( [0] => No [1] => Yes )
Array ( [0] => Active [1] => Inactive )
/** * @param string $true the label for the true value * @param string $false the label for the false value */ print_r(Enum::boolList()); print_r(Enum::boolList('Active', 'Inactive'));
gettype()
function in the sense, that it parses strings and returns the type based on its content. The function returns one of the following types:
$data = [ 'id' => 1, 'name' => 'Smith', 'date' => '2014/01/22', 'amount' => '4,323.23', 'relations' => ['spouse', 'children'] ]; foreach ($data as $k=>$v) { echo "<b>$k</b>: " . Enum::getType($v) . "<br>"; }
false
. The following parameters are supported.
array
: array the associative array to be converted.
transpose
: boolean whether to show keys as rows instead of columns. Defaults to false
. This parameter should be used only for a single dimensional associative array. If used for a multidimensional array, the sub array will be imploded as text. Check an example of usage in the getBrowser function below.
recursive
: boolean whether to recursively generate tables for multi-dimensional arrays. Defaults to false
typeHint
: boolean whether to show the data type as a hint. Defaults to true
.
null
: string the content to display for blank cells. Defaults to <span span class="not-set">NULL</span>
.
tableOptions
: array the HTML attributes for the table. Defaults to ['class' => 'table table-bordered table-striped']
keyOptions
: array the HTML attributes for the array key. Defaults to []
valueOptions
: array the HTML attributes for the array value. Defaults to ['style' => 'cursor: default; border-bottom: 1px #aaa dashed;']
id | name | birthday | commission | active |
---|---|---|---|---|
1 | John | 01-Jul-1976 | 4,500.50 | true |
2 | Scott | 26-Feb-1980 | 1,300.40 | true |
3 | Mary | 1990-02-10 | (not set) | false |
4 | Lisa | 17-Dec-1982 | -900.34 | true |
$data = [ ['id' => 1, 'name' => 'John', 'birthday' => '01-Jul-1976', 'commission'=>'4,500.50', 'active' => true], [2, 'Scott', '26-Feb-1980', '1,300.40', true], [3, 'Mary', '1990-02-10', null, false], [4, 'Lisa', '17-Dec-1982', '-900.34', true], ]; echo Enum::array2table($data);
3.145.89.89
3.145.89.89
/** * @param boolean $filterLocal whether to filter local & LAN IP */ echo Enum::userIP(); echo Enum::userIP(false);
common
: boolean whether to validate the most common browsers only. Defaults to false
. For quicker performance or for just checking the most commonly used browsers, set this to true.
browsers
: array the function validates most of the browsers - but if you choose, you can pass this list as key value pairs. The array key is the browser code (in lower case) as detected in the user agent string. The array value is the description/full name for the browser.
agent
: string the complete user agent string.
code
: string the browser code in lower case.
name
: string the full name of the browser.
version
: float the detected browser version (only the major and minor versions are shown).
platform
: string the platform on which the browser is running.
Your Browser Details
agent | Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com) | code | other | name | Other | version | ? | platform | Unknown |
---|
echo '<p class="lead">Your Browser Details</p>'; echo Enum::array2table(Enum::getBrowser(), true);
Comments & Discussion
Note
You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.
The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.