本文整理汇总了PHP中array_diff_key函数的典型用法代码示例。如果您正苦于以下问题:PHP array_diff_key函数的具体用法?PHP array_diff_key怎么用?PHP array_diff_key使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_diff_key函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(PhutilArgumentParser $args)
{
$console = PhutilConsole::getConsole();
$ids = $args->getArg('id');
if (!$ids) {
throw new PhutilArgumentUsageException(pht("Use the '%s' flag to specify one or more SMS messages to show.", '--id'));
}
$messages = id(new PhabricatorSMS())->loadAllWhere('id IN (%Ld)', $ids);
if ($ids) {
$ids = array_fuse($ids);
$missing = array_diff_key($ids, $messages);
if ($missing) {
throw new PhutilArgumentUsageException(pht('Some specified SMS messages do not exist: %s', implode(', ', array_keys($missing))));
}
}
$last_key = last_key($messages);
foreach ($messages as $message_key => $message) {
$info = array();
$info[] = pht('PROPERTIES');
$info[] = pht('ID: %d', $message->getID());
$info[] = pht('Status: %s', $message->getSendStatus());
$info[] = pht('To: %s', $message->getToNumber());
$info[] = pht('From: %s', $message->getFromNumber());
$info[] = null;
$info[] = pht('BODY');
$info[] = $message->getBody();
$info[] = null;
$console->writeOut('%s', implode("\n", $info));
if ($message_key != $last_key) {
$console->writeOut("\n%s\n\n", str_repeat('-', 80));
}
}
}
示例2: getReplacementOptions
/**
* Returns a list of image style replacement options.
*
* @return array
* An option list suitable for the form select '#options'.
*/
protected function getReplacementOptions()
{
if (!isset($this->replacementOptions)) {
$this->replacementOptions = array_diff_key(image_style_options(), [$this->getEntity()->id() => '']);
}
return $this->replacementOptions;
}
示例3: UnsentSubscribers
/**
* Returns a DataObjectSet containing the subscribers who have never been sent this Newsletter
*
*/
function UnsentSubscribers()
{
// Get a list of everyone who has been sent this newsletter
$sent_recipients = DataObject::get("Newsletter_SentRecipient", "ParentID='" . $this->ID . "'");
// If this Newsletter has not been sent to anyone yet, $sent_recipients will be null
if ($sent_recipients != null) {
$sent_recipients_array = $sent_recipients->toNestedArray('MemberID');
} else {
$sent_recipients_array = array();
}
// Get a list of all the subscribers to this newsletter
$subscribers = DataObject::get('Member', "`GroupID`='" . $this->Parent()->GroupID . "'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`");
// If this Newsletter has no subscribers, $subscribers will be null
if ($subscribers != null) {
$subscribers_array = $subscribers->toNestedArray();
} else {
$subscribers_array = array();
}
// Get list of subscribers who have not been sent this newsletter:
$unsent_subscribers_array = array_diff_key($subscribers_array, $sent_recipients_array);
// Create new data object set containing the subscribers who have not been sent this newsletter:
$unsent_subscribers = new DataObjectSet();
foreach ($unsent_subscribers_array as $key => $data) {
$unsent_subscribers->push(new ArrayData($data));
}
return $unsent_subscribers;
}
示例4: __construct
public function __construct($name, array $cd = array())
{
$this->setPhpName($name);
// elementary key verification
$illegalKeys = array_diff_key($cd, array_flip(array('columns', 'tableName', 'inheritance', 'i18n', 'indexes', 'options')));
if ($illegalKeys) {
throw new sfDoctrineSchemaException(sprintf('Invalid key "%s" in description of class "%s"', array_shift(array_keys($illegalKeys)), $name));
}
if (isset($cd['inheritance'])) {
$this->setInheritance($cd['inheritance']);
}
// set i18n
if (isset($cd['i18n'])) {
$this->setI18n($cd['i18n']);
}
// add indexes
if (isset($cd['indexes'])) {
$this->addIndexes($cd['indexes']);
}
// add options
if (isset($cd['options'])) {
$this->addOptions($cd['options']);
}
// add columns
if (isset($cd['columns'])) {
foreach ($cd['columns'] as $colName => $column) {
$docCol = new sfDoctrineColumnSchema($colName, $column);
$this->addColumn($docCol);
}
}
}
示例5: loadVariationByFallback
/**
* @SuppressWarnings(PHPMD.ElseExpression)
* {@inheritDoc}
*/
public function loadVariationByFallback(Product $parentProduct, array $attributes)
{
$variation = false;
if ($this->isProductHasSwatch($parentProduct) && $parentProduct->getDocumentSource() !== null) {
$documentSource = $parentProduct->getDocumentSource();
$childrenIds = isset($documentSource['children_ids']) ? $documentSource['children_ids'] : [];
if (!empty($childrenIds)) {
$childrenIds = array_map('intval', $childrenIds);
$productCollection = $this->productCollectionFactory->create();
$productCollection->addIdFilter($childrenIds);
$configurableAttributes = $this->getAttributesFromConfigurable($parentProduct);
$allAttributesArray = [];
foreach ($configurableAttributes as $attribute) {
foreach ($attribute->getOptions() as $option) {
$allAttributesArray[$attribute['attribute_code']][] = (int) $option->getValue();
}
}
$resultAttributesToFilter = array_merge($attributes, array_diff_key($allAttributesArray, $attributes));
$this->addFilterByAttributes($productCollection, $resultAttributesToFilter);
$variationProduct = $productCollection->getFirstItem();
if ($variationProduct && $variationProduct->getId()) {
$variation = $this->productRepository->getById($variationProduct->getId());
}
}
} else {
$variation = parent::loadVariationByFallback($parentProduct, $attributes);
}
return $variation;
}
示例6: save
public function save()
{
if (!$this->object) {
throw new Exception('Call setObject() before save()!');
}
$actor = $this->requireActor();
$src = $this->object->getPHID();
if ($this->implicitSubscribePHIDs) {
$unsub = PhabricatorEdgeQuery::loadDestinationPHIDs($src, PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER);
$unsub = array_fill_keys($unsub, true);
$this->implicitSubscribePHIDs = array_diff_key($this->implicitSubscribePHIDs, $unsub);
}
$add = $this->implicitSubscribePHIDs + $this->explicitSubscribePHIDs;
$del = $this->unsubscribePHIDs;
// If a PHID is marked for both subscription and unsubscription, treat
// unsubscription as the stronger action.
$add = array_diff_key($add, $del);
if ($add || $del) {
$u_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER;
$s_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_SUBSCRIBER;
$editor = new PhabricatorEdgeEditor();
foreach ($add as $phid => $ignored) {
$editor->removeEdge($src, $u_type, $phid);
$editor->addEdge($src, $s_type, $phid);
}
foreach ($del as $phid => $ignored) {
$editor->removeEdge($src, $s_type, $phid);
$editor->addEdge($src, $u_type, $phid);
}
$editor->save();
}
}
示例7: LinkWithSearch
public function LinkWithSearch($extraParamStr = '')
{
$params = array_diff_key($this->request->getVars(), array('url' => null));
parse_str($extraParamStr, $extraParams);
$params = array_merge($params, (array) $extraParams);
return Controller::join_links($this->Link(), '?' . http_build_query($params));
}
示例8: check_setup_settings
function check_setup_settings(&$settings = array())
{
if (isset($settings['show_on'])) {
$invalid_settings = array_diff_key($settings['show_on'], $this->settings['show_on']);
if (!empty($invalid_settings)) {
throw new Resume_Exception('Invalid show_on settings supplied to setup(): "' . implode('", "', array_keys($invalid_settings)) . '"');
}
}
if (isset($settings['show_on']['post_formats'])) {
$settings['show_on']['post_formats'] = (array) $settings['show_on']['post_formats'];
}
if (isset($settings['show_on']['post_path'])) {
$page = get_page_by_path($settings['show_on']['post_path']);
if ($page) {
$settings['show_on']['page_id'] = $page->ID;
} else {
$settings['show_on']['page_id'] = -1;
}
}
// Transform category slug to taxonomy + term slug + term id
if (isset($settings['show_on']['category'])) {
$term = get_term_by('slug', $settings['show_on']['category'], 'category');
if ($term) {
$settings['show_on']['tax_slug'] = $term->taxonomy;
$settings['show_on']['tax_term'] = $term->slug;
$settings['show_on']['tax_term_id'] = $term->term_id;
}
}
return parent::check_setup_settings($settings);
}
示例9: initUserAcl
/**
* initUserAcl() - Bind user specific ACL with user session.
*
* @return Zend_Acl
*/
protected function initUserAcl()
{
$authContent = Zend_Auth::getInstance()->getStorage()->read();
if (!is_array($authContent)) {
self::getLogger()->debug('Fresh visitor');
$remoteAcl = new Zend_Session_Namespace('remoteAcl');
if (!isset($remoteAcl->userInfo)) {
$remoteAcl->redirectedFrom = array_intersect_key($this->getRequest()->getParams(), $this->getRequest()->getUserParams());
$remoteAcl->redirectedParams = array_diff_key($this->getRequest()->getParams(), $this->getRequest()->getUserParams());
self::getLogger()->debug('Redirecting to "' . self::AUTH_URL . '", redirecting from');
self::getLogger()->debug($remoteAcl->redirectedFrom);
$this->getResponse()->setRedirect(self::AUTH_URL, 303);
return;
} else {
Zend_Registry::get('logger')->debug('User has logged in auth module');
}
$commonAcl = self::getCache()->load('commonAcl');
if ($commonAcl === false) {
$commonAcl = self::initAcl();
} else {
Zend_Registry::get('logger')->debug('Common ACL from Cache.');
}
$acl = $commonAcl['acl'];
$userInfo = $remoteAcl->userInfo;
$userRoles = array_intersect($userInfo['roles'], $commonAcl['dbRoles']);
Zend_Registry::get('logger')->debug('Module Roles of ' . $userInfo['identity']);
Zend_Registry::get('logger')->debug($userRoles);
$acl->addRole($userInfo['identity'], $userRoles);
$userInfo['acl'] = $acl;
Zend_Auth::getInstance()->getStorage()->write($userInfo);
Zend_Registry::get('logger')->debug($userInfo['identity'] . ' specific ACL saved in session.');
}
}
示例10: __construct
/**
*
* @param array $options_array keys: {
* @type EEM_Base $model
* @type EE_Base_Class $model_object
* @type array $subsection_args array keys should be subsection names (that either do or will exist), and values are the arrays as you would pass them to that subsection
* }
* @throws EE_Error
*/
public function __construct($options_array = array())
{
if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
$this->_model = $options_array['model'];
}
if (!$this->_model || !$this->_model instanceof EEM_Base) {
throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", "event_espresso")));
}
if (isset($options_array['subsection_args'])) {
$subsection_args = $options_array['subsection_args'];
} else {
$subsection_args = array();
}
//gather fields and relations to convert to inputs
//but if they're just going to exclude a field anyways, don't bother converting it to an input
$exclude = $this->_subsections;
if (isset($options_array['exclude'])) {
$exclude = array_merge($exclude, array_flip($options_array['exclude']));
}
$model_fields = array_diff_key($this->_model->field_settings(), $exclude);
$model_relations = array_diff_key($this->_model->relation_settings(), $exclude);
//convert fields and relations to inputs
$this->_subsections = array_merge($this->_convert_model_fields_to_inputs($model_fields), $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), $this->_subsections);
parent::__construct($options_array);
if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) {
$this->populate_model_obj($options_array['model_object']);
}
}
示例11: shortcode
/**
* [s2Member-Summary] Shortcode.
*
* @package s2Member\Shortcodes
* @since 150712
*
* @attaches-to ``add_shortcode('s2Member-Summary');``
*
* @param array $attr An array of Attributes.
* @param string $content Content inside the Shortcode.
* @param string $shortcode The actual Shortcode name itself.
*
* @return string Summary widget.
*/
public static function shortcode($attr_args_options = array(), $content = '', $shortcode = '')
{
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('c_ws_plugin__s2member_pro_before_sc_summary', get_defined_vars());
unset($__refs, $__v);
// Housekeeping.
$attr_args_options = (array) $attr_args_options;
$default_attr = array('show_login_if_not_logged_in' => '0');
$attr = array_merge($default_attr, $attr_args_options);
$attr = array_intersect_key($attr, $default_attr);
$default_args = array('before_widget' => '', 'before_title' => '<h3>', 'after_title' => '</h3>', 'after_widget' => '');
$args = array_merge($default_args, $attr_args_options);
$args = array_intersect_key($args, $default_args);
$options = array_diff_key($attr_args_options, $attr, $args);
if (!is_user_logged_in() && !filter_var($attr['show_login_if_not_logged_in'], FILTER_VALIDATE_BOOLEAN)) {
$summary = '';
} else {
ob_start();
// Begin output buffering.
c_ws_plugin__s2member_pro_login_widget::___static_widget___($args, $options);
$summary = ob_get_clean();
}
if ($summary) {
// Wrapper for CSS styling.
$summary = '<div class="ws-plugin--s2member-sc-summary">' . $summary . '</div>';
}
return apply_filters('c_ws_plugin__s2member_pro_sc_summary', $summary, get_defined_vars());
}
示例12: syncAll
/**
* Syncronise all file templates to the database.
* @return void
*/
public static function syncAll()
{
$templates = self::make()->listRegisteredTemplates();
$dbTemplates = self::lists('is_custom', 'code');
$newTemplates = array_diff_key($templates, $dbTemplates);
/*
* Clean up non-customized templates
*/
foreach ($dbTemplates as $code => $is_custom) {
if ($is_custom) {
continue;
}
if (!array_key_exists($code, $templates)) {
self::whereCode($code)->delete();
}
}
/*
* Create new templates
*/
foreach ($newTemplates as $code => $description) {
$sections = self::getTemplateSections($code);
$layoutCode = array_get($sections, 'settings.layout', 'default');
$template = self::make();
$template->code = $code;
$template->description = $description;
$template->is_custom = 0;
$template->layout_id = MailLayout::getIdFromCode($layoutCode);
$template->forceSave();
}
}
示例13: setup_posted_data
private function setup_posted_data()
{
$posted_data = (array) $_POST;
$posted_data = array_diff_key($posted_data, array('_wpnonce' => ''));
$posted_data = $this->sanitize_posted_data($posted_data);
$tags = $this->contact_form->form_scan_shortcode();
foreach ((array) $tags as $tag) {
if (empty($tag['name'])) {
continue;
}
$name = $tag['name'];
$value = '';
if (isset($posted_data[$name])) {
$value = $posted_data[$name];
}
$pipes = $tag['pipes'];
if (WPCF7_USE_PIPE && $pipes instanceof WPCF7_Pipes && !$pipes->zero()) {
if (is_array($value)) {
$new_value = array();
foreach ($value as $v) {
$new_value[] = $pipes->do_pipe(wp_unslash($v));
}
$value = $new_value;
} else {
$value = $pipes->do_pipe(wp_unslash($value));
}
}
$posted_data[$name] = $value;
}
$this->posted_data = apply_filters('wpcf7_posted_data', $posted_data);
return $this->posted_data;
}
示例14: _afterLoad
/**
* Store new messages in database and remove outdated messages
*
* @return $this|\Magento\Framework\Model\ModelResource\Db\AbstractDb
*/
public function _afterLoad()
{
$messages = $this->_messageList->asArray();
$persisted = [];
$unread = [];
foreach ($messages as $message) {
if ($message->isDisplayed()) {
foreach ($this->_items as $persistedKey => $persistedMessage) {
if ($message->getIdentity() == $persistedMessage->getIdentity()) {
$persisted[$persistedKey] = $persistedMessage;
continue 2;
}
}
$unread[] = $message;
}
}
$removed = array_diff_key($this->_items, $persisted);
foreach ($removed as $removedItem) {
$removedItem->delete();
}
foreach ($unread as $unreadItem) {
$item = $this->getNewEmptyItem();
$item->setIdentity($unreadItem->getIdentity())->setSeverity($unreadItem->getSeverity())->save();
}
if (count($removed) || count($unread)) {
$this->_unreadMessages = $unread;
$this->clear();
$this->load();
} else {
parent::_afterLoad();
}
return $this;
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$jobId = $input->getArgument('job-id');
$stats = $this->getBeanstalk()->statsJob($jobId);
$output->writeln("<info>[Job ID: {$jobId}]</info>");
$table = new Table($output);
$table->setStyle('compact');
$details = array_intersect_key($stats, array_flip(['tube', 'state']));
foreach ($details as $detail => $value) {
if ($detail == 'state' && $value == 'buried') {
$value = "<error>{$value}</error>";
}
$table->addRow([$detail, $value]);
}
$table->render();
$created = time();
$table = new Table($output);
$stats = array_diff_key($stats, array_flip(['id', 'tube', 'state']));
$table->setHeaders(['Stat', 'Value']);
foreach ($stats as $stat => $value) {
if ($stat == 'age') {
$created = time() - (int) $value;
$dt = date('Y-m-d H:i:s', $created);
$table->addRow(['created', $dt]);
} elseif ($stat == 'delay') {
$dt = date('Y-m-d H:i:s', $created + (int) $value);
$table->addRow(['scheduled', $dt]);
}
$table->addRow([$stat, $value]);
}
$table->render();
}