当前位置: 首页>>代码示例>>PHP>>正文


PHP Arr::is_assoc方法代码示例

本文整理汇总了PHP中Arr::is_assoc方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::is_assoc方法的具体用法?PHP Arr::is_assoc怎么用?PHP Arr::is_assoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Arr的用法示例。


在下文中一共展示了Arr::is_assoc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: importData

 /**
  * Imports data to the specified model
  */
 public static function importData($data, $model, $auto_backup = true, $lang = null)
 {
     \CMF\Doctrine\Extensions\Timestampable::disableListener();
     // Allow ourselves some room, this could take a while!
     try {
         set_time_limit(0);
         ini_set('memory_limit', '256M');
     } catch (\Exception $e) {
     }
     // Reset updated entities
     static::$_updatedEntities = array();
     // Normalise the data so we always have a collection
     if (is_array($data) && is_array(@$data['data']) && \Arr::is_assoc($data['data'])) {
         $data['data'] = array($data['data']);
     }
     try {
         // Loop through and import each external entity
         foreach ($data['data'] as $entity) {
             $entity = static::createOrUpdateEntity($entity, $model, $data, $lang);
             \D::manager()->flush();
         }
         static::processDeletions($model);
         \D::manager()->flush();
         // Try and repair any trees that may have been corrupted during the import
         static::repairTrees(array_keys(static::$_updatedEntities));
         \CMF\Doctrine\Extensions\Timestampable::enableListener();
     } catch (\Exception $e) {
         \CMF\Doctrine\Extensions\Timestampable::enableListener();
         return array('success' => false, 'message' => $e->getMessage());
     }
     return array('success' => true, 'message' => \Lang::get('admin.messages.import_success'));
 }
开发者ID:soundintheory,项目名称:fuel-cmf,代码行数:35,代码来源:Importer.php

示例2: test_is_assoc

 public function test_is_assoc()
 {
     $index = array('one', 'two');
     $assoc = array('one' => 'foo', 'two' => 'bar');
     $mixed = array('one' => 'foo', 'bar');
     $this->assert_false(Arr::is_assoc($index))->assert_true(Arr::is_assoc($assoc))->assert_true(Arr::is_assoc($mixed));
 }
开发者ID:banks,项目名称:unittest,代码行数:7,代码来源:arr.php

示例3: __construct

 /**
  * Ensures there is a choices array set.
  *
  * @param  array  $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (empty($this->choices)) {
         // Ensure we have choices to gather values from
         throw new Kohana_Exception(':class must have a `choices` property set', array(':class' => get_class($this)));
     }
     if (in_array(NULL, $this->choices)) {
         // Set allow_null to TRUE if we find a NULL value
         $this->allow_null = TRUE;
     } elseif ($this->allow_null) {
         // We're allowing NULLs but the value isn't set. Create it so validation won't fail.
         array_unshift($this->choices, NULL);
     }
     // Select the first choice
     reset($this->choices);
     if (!Arr::is_assoc($this->choices)) {
         // Convert non-associative values to associative ones
         $this->choices = array_combine($this->choices, $this->choices);
     }
     if (!array_key_exists('default', $options)) {
         // Set the default value from the first choice in the array
         $this->default = key($this->choices);
         if ($this->choices[$this->default] === NULL) {
             // Set the default to NULL instead of using the key which is an empty string for NULL values
             $this->default = NULL;
         }
     }
     // Add a rule to validate that the value is proper
     $this->rules[] = array('array_key_exists', array(':value', $this->choices));
 }
开发者ID:piotrtheis,项目名称:jelly,代码行数:36,代码来源:enum.php

示例4: set

 /**
  * Set a new alert.
  *
  * <code>
  * // Embed values with sprintf
  * Alert::set(Alert::INFO, 'Text: %s', array('Embed values with sprintf in text'), 'Subejct: %s');
  *
  * // Embed values with strtr
  * Alert::set(Alert::INFO, 'Text: :string', array(':string' => 'Embed values with strtr'), 'Subject: :string');
  *
  * // Render normal
  * Alert::set(Alert::INFO, 'INFO Text');
  *
  * // Render normal with subject
  * Alert::set(Alert::INFO, 'INFO Text', array(), 'INFO Subject');
  *
  * // Render as block
  * Alert::set(Alert::INFO, 'INFO Text', array(), null, true);
  *
  * // Render as block with subject
  * Alert::set(Alert::INFO, 'INFO Text Block', array(), 'INFO Subject Block', true);
  * </code>
  *
  * @param string $type    alert type (e.g. Alert::SUCCESS)
  * @param mixed  $text    alert text
  * @param array  $values  values to replace with sprintf or strtr
  * @param null   $subject subject or heading
  * @param bool   $block   render as block alert
  *
  * @uses Arr::is_assoc
  * @uses Session::instance
  * @return void
  */
 public static function set($type, $text, array $values = array(), $subject = null, $block = false)
 {
     if (empty($values) === false) {
         if (Arr::is_assoc($values)) {
             // Insert the values into the alert
             $text = strtr($text, $values);
             $subject = strtr($subject, $values);
         } else {
             $tmp_values = $values;
             // The target string goes first
             array_unshift($values, $text);
             // Insert the values into the alert
             $text = call_user_func_array('sprintf', $values);
             $values = $tmp_values;
             // The target string goes first
             array_unshift($values, $subject);
             // Insert the values into the alert
             $subject = call_user_func_array('sprintf', $values);
         }
     }
     // Load existing alerts
     $alerts = Alert::get();
     // Append a new alert
     $alerts[] = array('type' => $type, 'text' => $text, 'subject' => $subject, 'block' => $block);
     // Store the updated alerts
     Session::instance()->set(Alert::$_session_key, $alerts);
 }
开发者ID:nexeck,项目名称:kohana-alert,代码行数:60,代码来源:alert.php

示例5: xml

 /**
  * Convert an array to XML string
  *
  * @static
  * @param   array   $array
  * @param   string  $root
  * @param   SimpleXMLElement  $xml
  * @return  string
  */
 public static function xml(array $array, $root = 'data', SimpleXMLElement &$xml = null)
 {
     // Initialize
     if (is_null($xml)) {
         $xml = simplexml_load_string('<?xml version="1.0" encoding="' . Kohana::$charset . '"?><' . $root . ' />');
     }
     foreach ($array as $key => $value) {
         // No numeric keys in our xml please!
         $numeric = false;
         if (is_numeric($key)) {
             $numeric = true;
             $key = Inflector::singular($root);
         }
         // Valid XML name
         $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key);
         // Recursive call required for array values
         if (is_array($value)) {
             $node = true || Arr::is_assoc($value) || $numeric ? $xml->addChild($key) : $xml;
             self::xml($value, $key, $node);
         } else {
             $xml->addChild($key, htmlspecialchars($value));
         }
     }
     return $xml->asXML();
 }
开发者ID:netbiel,项目名称:core,代码行数:34,代码来源:arr.php

示例6: action_execute

 /**
  * Handles the request to execute a task.
  *
  * Responsible for parsing the tasks to execute & also any config items that
  * should be passed to the tasks
  */
 public function action_execute()
 {
     if (empty($this->_task)) {
         return $this->action_help();
     }
     $task = $this->_retrieve_task();
     $defaults = $task->get_config_options();
     if (!empty($defaults)) {
         if (Arr::is_assoc($defaults)) {
             $options = array_keys($defaults);
             $options = call_user_func_array(array('CLI', 'options'), $options);
             $config = Arr::merge($defaults, $options);
         } else {
             // Old behavior
             $config = call_user_func_array(array('CLI', 'options'), $defaults);
         }
     } else {
         $config = array();
     }
     // Validate $config
     $validation = Validation::factory($config);
     $validation = $task->build_validation($validation);
     if (!$validation->check()) {
         echo View::factory('minion/error/validation')->set('errors', $validation->errors($task->get_errors_file()));
     } else {
         // Finally, run the task
         echo $task->execute($config);
     }
 }
开发者ID:reflectivedevelopment,项目名称:jfh-lib,代码行数:35,代码来源:minion.php

示例7: set_global

 public final function set_global($key, $value = NULL)
 {
     if (is_array($key) and Arr::is_assoc($key)) {
         Kostache::$globals = Arr::merge(Kostache::$globals, $key);
     } else {
         Kostache::$globals[$key] = $value;
     }
 }
开发者ID:raeldc,项目名称:kojo-plugin,代码行数:8,代码来源:kostache.php

示例8: __construct

 public function __construct($class)
 {
     $props = $class::observers(get_class($this));
     $this->_relations = \Arr::is_assoc($props['relations']) ? array($props['relations']) : $props['relations'];
     if (!empty($props['check_changed'])) {
         $this->_check_properties = isset($props['check_changed']['check_properties']) ? $props['check_changed']['check_properties'] : array();
         $this->_ignore_properties = isset($props['check_changed']['ignore_properties']) ? $props['check_changed']['ignore_properties'] : array();
     }
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:9,代码来源:updaterelationaltables.php

示例9: replacer

 public static function replacer($content = '', $data = array(), $other = array())
 {
     $other = (array) $other;
     $exploder = isset($other['exploder']) ? $other['exploder'] : '.';
     $replace_null = isset($other['replace_null']) ? $other['replace_null'] : false;
     $repeater = isset($other['repeater']) ? $other['repeater'] : false;
     $brackets = isset($other['brackets']) ? $other['brackets'] : array("{", "}");
     $op = $brackets[0];
     $cl = $brackets[1];
     if (!empty($repeater)) {
         preg_match_all('/' . preg_quote($op) . $repeater . '([^' . preg_quote($cl) . ']*)' . preg_quote($cl) . '(.*?)' . preg_quote($op) . '\\/' . $repeater . preg_quote($cl) . '/is', $content, $repeater_matches);
         if (!empty($repeater_matches[0])) {
             foreach ($repeater_matches[0] as $k => $match) {
                 $path = '';
                 if (!empty($repeater_matches[1][$k])) {
                     $path = str_replace(':', '', $repeater_matches[1][$k]);
                 }
                 $sub_data = Arr::getVal($data, explode('.', $path), array());
                 if (!Arr::is_assoc($sub_data)) {
                     $sub_content = '';
                     foreach ($sub_data as $i => $sub_data_array) {
                         $sub_content .= self::replacer($repeater_matches[2][$k], $sub_data_array);
                     }
                     $content = str_replace($repeater_matches[0][$k], $sub_content, $content);
                 }
             }
         }
     }
     preg_match_all('/' . preg_quote($op) . '([^(' . $cl . '|' . $op . '| )]*?)' . preg_quote($cl) . '/i', $content, $curly_matches);
     if (isset($curly_matches[1]) && !empty($curly_matches[1])) {
         foreach ($curly_matches[1] as $match) {
             $value = Arr::getVal($data, explode($exploder, $match));
             if (is_string($value) and !empty($other['nl2br'])) {
                 $value = nl2br($value);
             }
             if (!is_null($value)) {
                 if (is_array($value)) {
                     $content = str_replace($op . $match . $cl, var_export($value, true), $content);
                 } else {
                     if (!empty($other['escape'])) {
                         $content = str_replace($op . $match . $cl, htmlspecialchars($value), $content);
                     } else {
                         $content = str_replace($op . $match . $cl, $value, $content);
                     }
                 }
             } else {
                 if ($replace_null === true) {
                     $content = str_replace($op . $match . $cl, '', $content);
                 }
             }
         }
     }
     return $content;
 }
开发者ID:ejailesb,项目名称:repo_empr,代码行数:54,代码来源:str.php

示例10: select_array

 /**
  * Choose the columns to select from, using an array.
  *
  * @param   array  list of column names or array aliases or key/value aliases array(alias => column)
  * @return  $this
  */
 public function select_array(array $columns)
 {
     if (Arr::is_assoc($columns)) {
         $columns_assoc = array();
         foreach ($columns as $alias => $column) {
             // Pass in the alias as the expected array($column, $alias) or only the string
             $columns_assoc[] = is_string($alias) ? array($column, $alias) : $column;
         }
         $columns = $columns_assoc;
     }
     $this->_select = array_merge($this->_select, $columns);
     return $this;
 }
开发者ID:joelpittet,项目名称:database,代码行数:19,代码来源:select.php

示例11: displayForm

 public static function displayForm($value, &$settings, $model)
 {
     $settings = static::settings($settings);
     if ($settings['array'] !== true) {
         $field_class = 'CMF\\Field\\Object\\Object';
         return $field_class::displayForm($value, $settings, $model);
     }
     if (!is_array($value)) {
         $value = array();
     }
     if (\Arr::is_assoc($value)) {
         $value = array($value);
     }
     $form = new ObjectForm($settings, $value);
     $content = '';
     return array('content' => $form->getContent($model), 'assets' => $form->assets, 'widget' => $settings['widget'], 'merge_data' => true, 'js_data' => $form->js_field_settings);
 }
开发者ID:soundintheory,项目名称:fuel-cmf,代码行数:17,代码来源:ArrayField.php

示例12: fill

 public function fill($x1, $y1, $x2, $y2, $color = array(0, 0, 0, 100))
 {
     is_string($color) and $color = $this->create_hex_color($color);
     if (is_array($color)) {
         if (\Arr::is_assoc($color)) {
             extract($color);
         } else {
             if (count($color) > 3) {
                 list($red, $green, $blue, $alpha) = $color;
             } else {
                 list($red, $green, $blue) = $color;
                 $alpha = 100;
             }
         }
         $alpha = 127 - floor($alpha * 1.27);
         $color = imagecolorallocatealpha($this->image_data, $red, $green, $blue, $alpha);
     }
     imagefilledrectangle($this->image_data, $x1, $y1, $x2, $y2, $color);
     return $this;
 }
开发者ID:indigophp,项目名称:fuel-core,代码行数:20,代码来源:gd.php

示例13: fill

 public function fill($x1, $y1, $x2, $y2, $color = array(0, 0, 0, 100))
 {
     is_string($color) and $color = $this->create_hex_color($color);
     if (is_array($color)) {
         if (\Arr::is_assoc($color)) {
             extract($color);
         } else {
             if (count($color) > 3) {
                 list($red, $green, $blue, $alpha) = $color;
             } else {
                 list($red, $green, $blue) = $color;
                 $alpha = 100;
             }
         }
         $alpha = round($alpha / 100, 1);
         $color = new \ImagickPixel('rgba(' . $red . ', ' . $green . ', ' . $blue . ', ' . str_replace(',', '.', $alpha) . ')');
     }
     $fill = new \ImagickDraw();
     $fill->setfillcolor($color);
     $fill->rectangle($x1, $y1, $x2, $y2);
     $this->imagick->drawimage($fill);
     return $this;
 }
开发者ID:indigophp,项目名称:fuel-core,代码行数:23,代码来源:imagick.php

示例14: merge

 /**
  * Merges one or more arrays recursively and preserves all keys.
  * Note that this does not work the same as [array_merge_recursive](http://php.net/array_merge_recursive)!
  *
  *     $john = array('name' => 'john', 'children' => array('fred', 'paul', 'sally', 'jane'));
  *     $mary = array('name' => 'mary', 'children' => array('jane'));
  *
  *     // John and Mary are married, merge them together
  *     $john = Arr::merge($john, $mary);
  *
  *     // The output of $john will now be:
  *     array('name' => 'mary', 'children' => array('fred', 'paul', 'sally', 'jane'))
  *
  * @param   array  initial array
  * @param   array  array to merge
  * @param   array  ...
  * @return  array
  */
 public static function merge(array $a1, array $a2)
 {
     $result = array();
     for ($i = 0, $total = func_num_args(); $i < $total; $i++) {
         // Get the next array
         $arr = func_get_arg($i);
         // Is the array associative?
         $assoc = Arr::is_assoc($arr);
         foreach ($arr as $key => $val) {
             if (isset($result[$key])) {
                 if (is_array($val) and is_array($result[$key])) {
                     if (Arr::is_assoc($val)) {
                         // Associative arrays are merged recursively
                         $result[$key] = Arr::merge($result[$key], $val);
                     } else {
                         // Find the values that are not already present
                         $diff = array_diff($val, $result[$key]);
                         // Indexed arrays are merged to prevent duplicates
                         $result[$key] = array_merge($result[$key], $diff);
                     }
                 } else {
                     if ($assoc) {
                         // Associative values are replaced
                         $result[$key] = $val;
                     } elseif (!in_array($val, $result, TRUE)) {
                         // Indexed values are added only if they do not yet exist
                         $result[] = $val;
                     }
                 }
             } else {
                 // New values are added
                 $result[$key] = $val;
             }
         }
     }
     return $result;
 }
开发者ID:Naatan,项目名称:FuelPHP-MangoDB,代码行数:55,代码来源:arr.php

示例15: getMapImage

 /**
  * Get a map image from the Google Maps static image API
  */
 public static function getMapImage($options, $force = false)
 {
     if ($is_single = \Arr::is_assoc($options)) {
         $options = array($options);
     }
     // Set up the dir for storing
     $dir = DOCROOT . 'uploads/maps';
     $dir_made = is_dir($dir) ? true : @mkdir($dir, 0775, true);
     if (!$dir_made) {
         throw new \Exception("The map upload directory could not be found or created!");
     }
     foreach ($options as $num => $settings) {
         // Allow offset to be applied
         $olat = \Arr::get($settings, 'lat', 54.443);
         $olng = \Arr::get($settings, 'lng', -3.063);
         $lat = $olat + \Arr::get($settings, 'latOffset', 0);
         $lng = $olng + \Arr::get($settings, 'lngOffset', 0);
         $width = \Arr::get($settings, 'width', 200);
         $height = \Arr::get($settings, 'height', 200);
         $scale = \Arr::get($settings, 'scale', 1);
         $marker = \Arr::get($settings, 'marker', false);
         $markerColor = \Arr::get($settings, 'markerColor', 'red');
         // Build the API url
         $url = 'http://maps.googleapis.com/maps/api/staticmap' . '?center=' . $lat . ',' . $lng . ($marker ? '&markers=color:' . $markerColor . '|' . $olat . ',' . $olng : '') . '&zoom=' . \Arr::get($settings, 'zoom', 11) . '&size=' . $width . 'x' . $height . '&scale=' . $scale . '&sensor=false';
         // Download the image
         $path = $dir . '/' . md5($url) . '.png';
         if (!file_exists($path) || $force) {
             $img = file_get_contents($url);
             @file_put_contents($path, $img);
         }
         // Set info back to the options
         $options[$num]['src'] = str_replace(DOCROOT, '', $path);
         $options[$num]['width'] = $width * $scale;
         $options[$num]['height'] = $height * $scale;
     }
     return $is_single ? $options[0] : $options;
 }
开发者ID:soundintheory,项目名称:fuel-cmf,代码行数:40,代码来源:GoogleMap.php


注:本文中的Arr::is_assoc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。