本文整理匯總了PHP中key_exists函數的典型用法代碼示例。如果您正苦於以下問題:PHP key_exists函數的具體用法?PHP key_exists怎麽用?PHP key_exists使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了key_exists函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getLabel
/**
* Overwrite the abstract method defined in Control, see parent comment
*
* @return string
*/
public function getLabel() : string
{
if (key_exists($this->getValue(), $this->getChoices())) {
return (string) $this->getChoices()[$this->getValue()];
}
return $this->getValue();
}
示例2: filter
/**
* Возвращает массив в виде дерева (многомерной иерархии)
* Позаимствовано с http://stackoverflow.com/questions/841014/nested-sets-php-array-and-transformation
*
* @param array $array Плоский массив
* @param string $depth Ключ массива в котором лежит номер уровня
* @param string $children Ключ массива в котором будут лежать дети
* @return array
*/
public function filter($array = array(), $depth = 'clevel', $children = 'children')
{
// Trees mapped
$trees = array();
$l = 0;
if (count($array) > 0) {
// Node Stack. Used to help building the hierarchy
$stack = array();
foreach ($array as $node) {
$item = $node;
//$item[$children] = array();
// Number of stack items
$l = count($stack);
// Check if we're dealing with different levels
while ($l > 0 && $stack[$l - 1][$depth] >= $item[$depth]) {
array_pop($stack);
$l--;
}
// Stack is empty (we are inspecting the root)
if ($l == 0) {
// Assigning the root node
$i = count($trees);
$trees[$i] = $item;
$stack[] =& $trees[$i];
} else {
// Add node to parent
$i = key_exists($children, $stack[$l - 1]) ? count($stack[$l - 1][$children]) : 0;
$stack[$l - 1][$children][$i] = $item;
$stack[] =& $stack[$l - 1][$children][$i];
}
}
}
return $trees;
}
示例3: _setEventStatus
protected function _setEventStatus($status)
{
$this->requireAuthentication();
$app = App::i();
if (!key_exists('id', $this->urlData)) {
$app->pass();
}
$entity = $this->getRequestedEntity();
if (!$entity) {
$app->pass();
}
$entity->checkPermission('@control');
if (isset($this->data['ids']) && $this->data['ids']) {
$ids = is_array($this->data['ids']) ? $this->data['ids'] : explode(',', $this->data['ids']);
$events = $app->repo('Event')->findBy(['id' => $ids]);
}
foreach ($events as $event) {
if (\MapasCulturais\Entities\Event::STATUS_ENABLED === $status) {
$event->publish();
} elseif (\MapasCulturais\Entities\Event::STATUS_DRAFT === $status) {
$event->unpublish();
}
}
$app->em->flush();
$this->json(true);
}
示例4: index
public function index(){
$days = 7;
$this -> assign('days', $days);
$where = array('token' => $this -> token);
$where['time'] = array('gt', time() - $days * 24 * 3600);
$where['module'] = array('neq', '');
$db = M('Share');
$items = $db -> where($where) -> select();
$datas = array();
if ($items){
foreach ($items as $item){
if (trim($item['module'])){
if (!key_exists($item['module'], $datas)){
$datas[$item['module']] = array('module' => $item['module'], 'count' => 1, 'moduleName' => funcDict :: moduleName($item['module']));
}else{
$datas[$item['module']]['count']++;
}
}
}
}
$xml = '<chart borderThickness="0" caption="' . $days . '日內分享統計" baseFontColor="666666" baseFont="宋體" baseFontSize="14" bgColor="FFFFFF" bgAlpha="0" showBorder="0" bgAngle="360" pieYScale="90" pieSliceDepth="5" smartLineColor="666666">';
if ($datas){
foreach ($datas as $item){
$xml .= '<set label="' . $item['moduleName'] . '" value="' . $item['count'] . '"/>';
}
}
$xml .= '</chart>';
$this -> assign('items', $items);
$this -> assign('xml', $xml);
$this -> assign('list', $datas);
$this -> assign('listinfo', 1);
$this -> assign('tab', 'stastic');
$this -> display();
}
示例5: tree
/**
* 指定店鋪的 商品分類 樹
* @param number $sid 店鋪ID
* @param string $status 狀態
*/
public function tree($sid, $status = null)
{
$status_view = array('default' => '所有', 'del' => '已刪除', 'forbid' => '禁用', 'allow' => '正常');
//默認是 所有 未刪除
//店鋪id必須有
$map['store_id'] = (int) $sid;
if ($map['store_id'] <= 0) {
$this->error('參數非法');
}
$store_M = new Model('Store');
$store_info = $store_M->find($map['store_id']);
if (empty($store_info)) {
$this->error('店鋪不存在');
}
$this->assign('store_info', $store_info);
$now_status = $status_view['default'];
if (isset($status) && key_exists($status, CategoryModel::$mystat)) {
//指定查詢狀態
$map['status'] = CategoryModel::$mystat[$status];
$now_status = $status_view[$status];
} else {
$map['status'] = array('EGT', 0);
//默認查詢狀態為未刪除的數據
}
$model = new CategoryModel();
$cate_tree = $model->ztreeArr($map);
$cate_tree = json_encode($cate_tree);
$this->assign('tree_json', $cate_tree);
//ztree json
$this->assign('now_status', $now_status);
//當前頁麵篩選的狀態
// 記錄當前列表頁的cookie
cookie(C('CURRENT_URL_NAME'), $_SERVER['REQUEST_URI']);
$this->display();
}
示例6: startthelog
function startthelog($logname, $quick = FALSE)
{
logit($logname, '-----------------------------------------------------------');
$line = '';
//logit($logname, $_SERVER['HTTP_REFERER']);
if (!$quick) {
// doing the dns lookup takes some extra time so use $quick to speed things up a bid
$line = gethostbyaddr($_SERVER["REMOTE_HOST"]);
if ($line == $_SERVER["REMOTE_ADDR"]) {
$line = '** No DNS entry found for calling IP';
}
$line = ' - ' . $line;
}
logit($logname, $_SERVER["REMOTE_ADDR"] . $line);
if (key_exists('HTTP_USER_AGENT', $_SERVER)) {
logit($logname, $_SERVER['HTTP_USER_AGENT'] . $line);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (substr(str_replace(chr(10), '', print_r($_POST, true)), 10) == '') {
logit($logname, 'Called as a POST, but NO values were passed in');
} else {
logit($logname, 'POST values: ' . substr(str_replace(chr(10), '', print_r($_POST, true)), 10));
}
}
if ($_SERVER["QUERY_STRING"] != '') {
logit($logname, 'GET param string: ' . $_SERVER["QUERY_STRING"]);
}
}
示例7: getNavigation
/**
* Return all navigation collection
*
* @param type $name
* @return array
*/
public function getNavigation($name)
{
if (!key_exists($name, $this->_navigations)) {
return null;
}
return $this->_navigations[$name];
}
示例8: AddPreLoadedImage
public function AddPreLoadedImage($strLoc)
{
if (!key_exists(MJaxTouchConfig::preloadImages, $this->arrConfig)) {
$this->arrConfig[MJaxTouchConfig::preloadImages] = array();
}
$this->arrConfig[MJaxTouchConfig::preloadImages][] = $strLoc;
}
示例9: save
public function save()
{
$name = basename($this->project->compiledFile, '.chm');
$dir = dirname($this->project->compiledFile);
if (!is_dir($dir)) {
throw new CException(Yii::t('yiiext', 'Directory "{directory} not available.".', array('{directory}' => $dir)));
}
if ($this->project->contentsFile === NULL) {
$this->project->contentsFile = $dir . '/' . $name . '.hhc';
}
if ($this->project->indexFile === NULL) {
$this->project->indexFile = $dir . '/' . $name . '.hhk';
}
if ($this->project->path === NULL) {
$this->project->path = $dir . '/' . $name . '.hhp';
}
$windows = $this->project->getWindows();
if ($this->project->defaultWindow === NULL || !key_exists($this->project->defaultWindow, $windows)) {
reset($windows);
$this->project->defaultWindow = current($windows)->id;
}
$this->toc->save($this->project->contentsFile);
$this->index->save($this->project->indexFile);
$this->project->save($this->project->path);
// generate project
$exeFile = dirname(__FILE__) . '/vendors/hhc.exe';
exec('"' . $exeFile . '" "' . $this->project->path . '"', $output, $return_var);
if (!file_exists($this->project->compiledFile)) {
throw new CException(Yii::t('yiiext', 'Cannot save .chm file "{file}".' . "\nReturn: {$return_var}\nOutput:\n" . implode("\n", $output), array('{file}' => $this->project->compiledFile)));
}
return $this->project->compiledFile;
}
示例10: setLocation
/**
* Sets the value of the location property.
*
* You can set the value of this property using a GeoPoint object or using an array,
*
* <code>
* // example with GeoPoint
* $entity->location = new GeoPoint(-45.123, -23.345);
*
* // example with arrays
* $entity->location = [-45.123, -23.345];
* $entity->location = ['x' => -45.123, 'y' => -23.345];
* $entity->location = ['longitude' => -45.123, 'latitude' => -23.345];
*
* </code>
*
* This method sets the value of the property _geoLocation with a PostGIS ST_Geography type.
*
* @param \MapasCulturais\Types\GeoPoint|array $location
*/
function setLocation($location)
{
$x = $y = null;
if (!$location instanceof GeoPoint) {
if (is_array($location) && key_exists('x', $location) && key_exists('y', $location)) {
$x = $location['x'];
$y = $location['y'];
} elseif (is_array($location) && key_exists('longitude', $location) && key_exists('latitude', $location)) {
$x = $location['longitude'];
$y = $location['latitude'];
} elseif (is_array($location) && count($location) === 2 && is_numeric($location[0]) && is_numeric($location[1])) {
$x = $location[0];
$y = $location[1];
} else {
throw new \Exception(App::txt('The location must be an instance of \\MapasCulturais\\Types\\GeoPoint or an array with two numeric values'));
}
$location = new GeoPoint($x, $y);
}
if (is_numeric($x) && is_numeric($y)) {
$rsm = new \Doctrine\ORM\Query\ResultSetMapping();
$sql = "SELECT ST_GeographyFromText('POINT({$location->longitude} {$location->latitude})') AS geo";
$rsm->addScalarResult('geo', 'geo');
$query = App::i()->em->createNativeQuery($sql, $rsm);
$this->_geoLocation = $query->getSingleScalarResult();
}
$this->location = $location;
}
示例11: render
public static function render($params = [])
{
$html = '';
/** Rendering breadcrumb show */
if (!empty($params)) {
foreach ($params as $j => $i) {
/** Prepping data */
$r = explode(':', $i);
/** Rendering breadcrumb list */
if (!empty(self::$array)) {
foreach (self::$array as $k => $v) {
if ($k == $r[0]) {
if ($j == count($params) - 1) {
$html .= '<li><a class="acitve-pages" >' . $v['title'] . '</a></li>';
} else {
if (key_exists(1, $r)) {
$html .= '<li><a href="' . $v['url'] . '/' . $r[1] . '" >' . $v['title'] . '</a></li>';
} else {
$html .= '<li><a href="' . $v['url'] . '" >' . $v['title'] . '</a></li>';
}
}
}
}
}
}
}
$html .= '';
return $html;
}
示例12: setDefine
/**
* Sets options for dbd.h
* @param string $define name of contstant to modify
* @param mixed $value value to set constant to
* @return boolean
*/
public function setDefine($define, $value)
{
if (key_exists($define, $this->dbdDefines)) {
/**@TODO: add sanitiy checking for define values */
switch ($define) {
/**
* String values need to be quoted
*/
case 'HOST':
case 'BINDHOST':
case 'EXECPROC_NULL':
case 'SHARED_SECRET':
case 'HIGHLIGHT_PREFIX':
case 'HIGHLIGHT_SUFFIX':
case 'SEPARATOR_BETWEEN_PREFIX_AND_DATA':
case 'INSTANCE_SEMAPHORE':
$value = "'" . $value . "'";
break;
default:
break;
}
$this->dbdDefines["{$define}"] = $value;
return true;
}
return false;
}
示例13: run
public function run()
{
$message = '';
$projectlist = new ProjectListModel();
$projectlist->read();
$projectIds = array_map(function ($e) {
return $e['id'];
}, $projectlist->entries);
$emptyQuestionTitles = 0;
foreach ($projectIds as $projectId) {
$project = new ProjectModel($projectId);
$activityEntries = ActivityListDto::getActivityForProject($project);
foreach ($activityEntries as $activity) {
if (key_exists('questionRef', $activity) && key_exists('question', $activity['content'])) {
$questionId = $activity['questionRef'];
$questionTitle = $activity['content']['question'];
if ($questionTitle == '') {
$emptyQuestionTitles++;
$questionModel = new QuestionModel($project, $questionId);
$activityModel = new ActivityModel($project, $activity['id']);
$newTitle = $questionModel->getTitleForDisplay();
$activityModel->actionContent['question'] = $newTitle;
$message .= "Fixing activity " . $activity['action'] . " with title '" . $newTitle . "'\n";
$activityModel->write();
}
}
}
}
if ($emptyQuestionTitles > 0) {
$message .= "\n\nFixed up {$emptyQuestionTitles} empty question titles in the activity log\n\n";
} else {
$message .= "\n\nNo empty question titles were found in the activity log \n\n";
}
return $message;
}
示例14: stream_read
function stream_read($count)
{
if (key_exists($this->s++, $this->lines)) {
return $this->lines[$this->s - 1];
}
return "";
}
示例15: weekbyhours
protected function weekbyhours()
{
$this->matrix = array();
foreach ($this->events as $event) {
$recur = new Recurrences($event);
foreach ($recur->recurrences as $recurrence) {
/* @var $recurrence When */
if ($recurrence->getFequency() == 'WEEKLY') {
foreach ($recurrence->getByDay() as $day) {
if ($day[0] == '+') {
$weekday = substr($day, 2);
$start = new \DateTime($event->getStart()->dateTime);
$time = $start->format('H:i');
if (!key_exists($time, $this->matrix)) {
$this->matrix[$time] = array();
}
$this->matrix[$time][$weekday][] = $event;
}
}
}
}
}
ksort($this->matrix);
return $this->matrix;
}