本文整理汇总了PHP中Arrays类的典型用法代码示例。如果您正苦于以下问题:PHP Arrays类的具体用法?PHP Arrays怎么用?PHP Arrays使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arrays类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($function, array $params = array())
{
$hooks = Utils::get('ThinHooks');
$res = null;
if (Arrays::exists($function, $hooks)) {
if (Arrays::exists('before', $hooks[$function])) {
$action = $hooks[$function]['before'];
if (is_callable($action, true, $before)) {
$res = $before();
}
}
if (null === $res) {
$res = '';
}
$res .= call_user_func_array($function, $params);
if (Arrays::exists('after', $hooks[$function])) {
$action = $hooks[$function]['after'];
if (is_callable($action, true, $after)) {
$res .= $after();
}
}
return $res;
} else {
return call_user_func_array($function, $params);
}
}
示例2: query
public function query($sql)
{
$resource = mssql_query($sql, $this->link);
if ($resource) {
if (is_resource($resource)) {
$i = 0;
$data = array();
while ($result = mssql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
mssql_free_result($resource);
$query = new Object();
$row = isset(Arrays::first($data)) ? Arrays::first($data) : array();
$query->setRow($row)->setRows($data)->setNumRows($i);
unset($data);
return $query;
} else {
return true;
}
} else {
trigger_error('Error: ' . mssql_get_last_message($this->link) . '<br />' . $sql);
exit;
}
}
示例3: splitArrayCategory
function splitArrayCategory($stat, $sep, $page)
{
$array = Arrays::getArray($stat);
$phrase = Phrases::getPhrase($stat);
$inserts = null;
for ($i = 0; $i < count($array); $i++) {
if ($i > 0) {
$inserts .= $sep;
}
if ($stat == "achievement") {
$img = "<img src='images/achievements/" . $array[$i] . ".png' class='img'> ";
} else {
if ($stat == "stat.killEntity" || $stat == "stat.entityKilledBy") {
$img = "<img src='images/mobs/" . $array[$i] . ".png' class='img'> ";
} else {
if ($stat != "stat") {
$img = "<img src='images/items/" . $array[$i] . ".png' class='img'> ";
}
}
}
$link = "top.php?do={$stat}&page={$page}&sort=" . $array[$i];
$asc = " <a href='{$link}&order=ASC'><img src='images/up.png' class='sort'></a>";
$desc = " <a href='{$link}&order=DESC'><img src='images/down.png' class='sort'></a>";
$inserts .= $img . $phrase[$i] . $asc . $desc;
}
return $inserts;
}
示例4: _element
protected function _element($data = '', $tab = '', $start = 0)
{
static $start;
$eof = eol();
$output = '';
$attrs = '';
$tab = str_repeat("\t", $start);
if (!is_array($data)) {
return $data . $eof;
} else {
foreach ($data as $k => $v) {
if (is_numeric($k)) {
$k = 'li';
}
$end = "/" . Arrays::getFirst(explode(' ', $k));
if (!is_array($v)) {
$output .= "{$tab}<{$k}>{$v}<{$end}>{$eof}";
} else {
$output .= $tab . "<{$k}>{$eof}" . $this->_element($v, $tab, $start++) . $tab . "<{$end}>" . $tab . $eof;
$start--;
}
}
}
return $output;
}
示例5: orderBy
public function orderBy($tab, $fieldOrder, $orderDirection = 'ASC')
{
$sortFunc = function ($key, $direction) {
return function ($a, $b) use($key, $direction) {
if ('ASC' == $direction) {
return $a[$key] > $b[$key];
} else {
return $a[$key] < $b[$key];
}
};
};
if (Arrays::is($fieldOrder) && !Arrays::is($orderDirection)) {
$t = array();
foreach ($fieldOrder as $tmpField) {
array_push($t, $orderDirection);
}
$orderDirection = $t;
}
if (!Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
$orderDirection = Arrays::first($orderDirection);
}
if (Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
for ($i = 0; $i < count($fieldOrder); $i++) {
usort($tab, $sortFunc($fieldOrder[$i], $orderDirection[$i]));
}
} else {
usort($tab, $sortFunc($fieldOrder, $orderDirection));
}
return $tab;
}
示例6: calculation_sheet_custom
public function calculation_sheet_custom($keys)
{
include_once APPPATH . "models/helperClasses/Calculation_Sheet.php";
$this->db->select("*");
$this->db->where(array('entryDate >=' => $keys['from_date'], 'entryDate <=' => $keys['to_date']));
if ($keys['company_id'] != 'all') {
$this->db->where('company_id', $keys['company_id']);
}
if ($keys['contractor_id'] != 'all') {
$this->db->where('contractor_id', $keys['contractor_id']);
}
if ($keys['product'] != 'all' && $keys['product'] != '') {
$this->db->where('product', $keys['product']);
}
if ($keys['product_type'] != 'all' && $keys['product_type'] != '') {
if ($_GET['product_type'] == 'black oil') {
$this->db->where('product_type', 'black oil');
}
if ($_GET['product_type'] == 'white oil') {
$this->db->where('product_type', 'white oil');
}
}
$result = $this->db->get('calculation_sheet_view')->result();
$calculation_sheet_white_oil = array();
foreach ($result as $record) {
array_push($calculation_sheet_white_oil, new Calculation_Sheet($record));
}
$grouped = Arrays::groupBy($calculation_sheet_white_oil, Functions::extractField('destination'), 'invoice_number');
ksort($grouped);
return $grouped;
}
示例7: findByIdSet
public function findByIdSet($idSet)
{
$ids = Arrays::toStringSQL($idSet, ",");
$sql = "SELECT id, login, firstname, lastname, email, online, gender, birthdate, avatar, lastActive\n\t\t\t\tFROM user \n\t\t\t\tWHERE id in ({$ids})";
$users = $this->execute($sql);
return $result = count($users) > 0 ? $users : null;
}
示例8: loadHttpData
/**
* Loads HTTP data.
* @return void
*/
public function loadHttpData()
{
$path = $this->getHtmlName();
// img_x or img['x']
$path = explode('[', strtr(str_replace(']', '', strpos($path, '[') === FALSE ? $path . '.x' : substr($path, 0, -2)), '.', '_'));
$this->setValue(Arrays::get($this->getForm()->getHttpData(), $path, NULL));
}
示例9: format
private function format($text = '', $parameters = array())
{
if (!Arrays::is($parameters) && 'NONE' == $parameters) {
return $text;
}
if (!Arrays::is($parameters) && isset($this->styles[$parameters])) {
$parameters = $this->styles[$parameters];
}
$codes = array();
$fg = isAke($parameters, 'fg', null);
$bg = isAke($parameters, 'bg', null);
if (!empty($fg)) {
$codes[] = $this->foreground[$fg];
}
if (!empty($bg)) {
$codes[] = $this->background[$bg];
}
foreach ($this->options as $option => $value) {
$paramOpt = isAke($parameters, $option, null);
if (!empty($paramOpt)) {
$codes[] = $value;
}
}
return "[" . implode(';', $codes) . 'm' . $text . "[0m";
}
示例10: connexion
public static function connexion()
{
$args = func_get_args();
$class = '\\Thin\\Db\\' . ucfirst(Inflector::lower(Arrays::first($args)));
array_shift($args);
return call_user_func_array([$class, 'instance'], $args);
}
示例11: getFileList
/**
* Returns the file list for a given directory
*
* @param string $strDir - the absolute local path to the directory (e.g. /dir/mydir)
* @param string $baseUrl - the relative uri (e.g. /tl_files/mydir)
* @param string $protectedBaseUrl - domain + request uri -> absUrl will be domain + request uri + ?file=$baseUrl/filename.ext
*
* @return array file list containing file objects.
*/
public static function getFileList($strDir, $baseUrl, $protectedBaseUrl = null)
{
$arrResult = array();
if (is_dir($strDir)) {
if ($handler = opendir($strDir)) {
while (($strFile = readdir($handler)) !== false) {
if (substr($strFile, 0, 1) == '.') {
continue;
}
$arrFile = array();
$arrFile['filename'] = htmlentities($strFile);
if ($protectedBaseUrl) {
$arrFile['absUrl'] = $protectedBaseUrl . (empty($_GET) ? '?' : '&') . 'file=' . urlencode($arrFile['absUrl']);
} else {
$arrFile['absUrl'] = str_replace('\\', '/', str_replace('//', '', $baseUrl . '/' . $strFile));
}
$arrFile['path'] = str_replace($arrFile['filename'], '', $arrFile['absUrl']);
$arrFile['filesize'] = self::formatSizeUnits(filesize(str_replace('\\', '/', str_replace('//', '', $strDir . '/' . $strFile))), true);
$arrResult[] = $arrFile;
}
closedir($handler);
}
}
Arrays::aasort($arrResult, 'filename');
return $arrResult;
}
示例12: __call
public function __call($method, $args)
{
if (true === $this->__has($method)) {
return $this->__fire($method, $args);
}
$reverse = strrev($method);
$last = $reverse[0];
if ('s' == $last) {
if (!count($args)) {
return isAke($this->values, $method);
} else {
$this->values[$method] = !Arrays::is($this->values[$method]) ? array() : $this->values[$method];
foreach ($args as $arg) {
array_push($this->values[$method], $arg);
}
}
return $this;
} else {
$method .= 's';
if (!count($args)) {
$val = isAke($this->values, $method);
return count($val) ? Arrays::first($val) : null;
} else {
$this->values[$method] = !Arrays::is($this->values[$method]) ? array() : $this->values[$method];
foreach ($args as $arg) {
array_push($this->values[$method], $arg);
}
}
return $this;
}
}
示例13: __call
public function __call($func, $argv)
{
if (substr($func, 0, 3) == 'get') {
$uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
$key = Inflector::lower($uncamelizeMethod);
if (isset($argv[0])) {
$environment = $argv[0];
} else {
$environment = APPLICATION_ENV;
}
return getConfig($key, $environment);
} elseif (substr($func, 0, 3) == 'set') {
$uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
$key = Inflector::lower($uncamelizeMethod);
$value = Arrays::first($argv);
if (isset($argv[1])) {
$environment = $argv[1];
} else {
$environment = 'all';
}
setConfig($key, $value, $environment);
return $this;
} elseif (substr($func, 0, 3) == 'has') {
$uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3)));
$key = Inflector::lower($uncamelizeMethod);
if (isset($argv[0])) {
$environment = $argv[0];
} else {
$environment = APPLICATION_ENV;
}
return null !== getConfig($key, $environment);
}
}
示例14: find
/**
* Search a value in a (multidimensional) array - replacement for array_search().
*
* This function returns the key of the element that contains the specified keyword.
* The element can be an array, it will be recursively scanned for the keyword.
* The key of the parent element (not the child element) which contains the keyword
* will be returned. If there are more than one elements with the specified keyword
* the key of the first found element will be returned. If nothing is found boolean
* FALSE will be returned.
*
* Example:
* <code>
* $mimeTypes = array(
* 'image/gif' => array('gif'),
* 'image/jpeg' => array('jpe', 'jpeg', 'jpg'),
* 'image/png' => array('png', 'x-png'),
* );
* echo Arrays::find($mimeTypes, 'jpg');
* // Output: image/jpeg
* </code>
*
* @param array Array to search in
* @param mxied Text to find
* @return mixed Key of array or false on failure
*/
public static function find(array $array, $keyword) {
foreach($array as $key => $value) {
if($keyword === $value || (is_array($value) == true && Arrays::find($array, $value) !== false)) {
return $key;
}
}
return false;
}
示例15: testColumn
/**
* @covers h4kuna\DataType\Basic\Arrays::column
* @todo Implement testColumn().
*/
public function testColumn()
{
$array = array(array('name' => 'Joe', 'id' => 1), array('name' => 'Doe', 'id' => 2), array('name' => 'Foo', 'id' => 3), array('name' => 'Bar', 'id' => 4));
$this->assertSame(array('Joe', 'Doe', 'Foo', 'Bar'), Arrays::column($array, 'name'));
$this->assertSame(array(1 => 'Joe', 2 => 'Doe', 3 => 'Foo', 4 => 'Bar'), Arrays::column($array, 'name', 'id'));
$this->assertSame(array(1 => array('name' => 'Joe', 'id' => 1), 2 => array('name' => 'Doe', 'id' => 2), 3 => array('name' => 'Foo', 'id' => 3), 4 => array('name' => 'Bar', 'id' => 4)), Arrays::column($array, NULL, 'id'));
$this->assertSame($array, Arrays::column($array));
}