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


PHP array_fill函数代码示例

本文整理汇总了PHP中array_fill函数的典型用法代码示例。如果您正苦于以下问题:PHP array_fill函数的具体用法?PHP array_fill怎么用?PHP array_fill使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: get

 function get()
 {
     $aim_table = I('aim_table');
     $aim_id = I('aim_id');
     $list = D('Comment')->getComment($aim_id, $aim_table);
     if ($list == null) {
         $list = array();
     }
     $sensitiveStr = C('SENSITIVE_WORDS');
     $sensitiveArr = explode(',', $sensitiveStr);
     $badkeywords = array_combine($sensitiveArr, array_fill(0, count($sensitiveArr), '***'));
     foreach ($badkeywords as $k => &$v) {
         // if (mb_strlen ( $k, 'utf8' ) <= 2) {
         // unset ( $badkeywords [$k] );
         // }
         if (empty($k)) {
             unset($badkeywords[$k]);
         }
     }
     foreach ($list as &$v) {
         $v['content'] = strtr($v['content'], $badkeywords);
         $v['content'] = parseComment($v['content']);
         $v['time'] = time_format($v['cTime']);
         // dump($v['content']);
     }
     // dump($list);
     $this->ajaxReturn($list, 'JSON');
 }
开发者ID:yxz1025,项目名称:weiphp3.0,代码行数:28,代码来源:WapController.class.php

示例2: Linear

 /**
  * Interpolate values in a matrice so that the total number of data points
  * in vert and horizontal axis are $aIntNbr more. For example $aIntNbr=2 will
  * make the data matrice have tiwce as many vertical and horizontal dta points.
  *
  * Note: This will blow up the matrcide in memory size in the order of $aInNbr^2
  *
  * @param  $ &$aData The original data matricde
  * @param  $aInNbr Interpolation factor
  * @return the interpolated matrice
  */
 function Linear(&$aData, $aIntFactor)
 {
     $step = pow(2, $aIntFactor - 1);
     $orig_cols = count($aData[0]);
     $orig_rows = count($aData);
     // Number of new columns/rows
     // N = (a-1) * 2^(f-1) + 1
     $p = pow(2, $aIntFactor - 1);
     $new_cols = $p * ($orig_cols - 1) + 1;
     $new_rows = $p * ($orig_rows - 1) + 1;
     $this->data = array_fill(0, $new_rows, array_fill(0, $new_cols, 0));
     // Initialize the new matrix with the values that we know
     for ($i = 0; $i < $new_rows; $i++) {
         for ($j = 0; $j < $new_cols; $j++) {
             $v = 0;
             if ($i % $step == 0 && $j % $step == 0) {
                 $v = $aData[$i / $step][$j / $step];
             }
             $this->data[$i][$j] = $v;
         }
     }
     for ($i = 0; $i < $new_rows - 1; $i += $step) {
         for ($j = 0; $j < $new_cols - 1; $j += $step) {
             $this->IntSquare($i, $j, $aIntFactor);
         }
     }
     return $this->data;
 }
开发者ID:samyscoub,项目名称:librenms,代码行数:39,代码来源:jpgraph_meshinterpolate.inc.php

示例3: __construct

 /**
  * Creates a new Salsa20 instance
  *
  * @param  string $key (32 bytes)
  * @param  string $iv (8 bytes)
  */
 public function __construct($key, $iv)
 {
     $this->useKey($key);
     $this->useIv($iv);
     $this->position = self::OUTPUT_LEN;
     $this->output = array_fill(0, self::OUTPUT_LEN, 0);
 }
开发者ID:xp-forge,项目名称:keepass,代码行数:13,代码来源:Salsa20.class.php

示例4: save

 public function save()
 {
     $values = get_object_vars($this);
     $filtered = null;
     foreach ($values as $key => $value) {
         if ($value !== null && $value !== '' && strpos($key, 'obj_') === false && $key !== 'id') {
             if ($value === false) {
                 $value = 0;
             }
             $filtered[$key] = $value;
         }
     }
     $columns = array_keys($filtered);
     if ($this->id) {
         $columns = join(" = ?, ", $columns);
         $columns .= ' = ?';
         $query = "UPDATE " . static::$table . " SET {$columns} WHERE id =" . $this->id;
     } else {
         $params = join(", ", array_fill(0, count($columns), "?"));
         $columns = join(", ", $columns);
         $query = "INSERT INTO " . static::$table . " ({$columns}) VALUES ({$params})";
     }
     $result = self::$database->execute($query, null, $filtered);
     if ($result) {
         $result = array('error' => false, 'message' => self::$database->getInsertedID());
     } else {
         $result = array('error' => true, 'message' => self::$database->getError());
     }
     return $result;
 }
开发者ID:ricardo-pcan,项目名称:cgfie-framework,代码行数:30,代码来源:orm.php

示例5: run

 public function run()
 {
     $this->requireDataset('Huge');
     $doc = array('key' => str_repeat("var", 1000));
     $docs = array_fill(0, 5000, $doc);
     // Test 1: Retrieve only the first 100 results. Then delete the cursor. This should trigger a stop message.
     $cursor = r\db('Huge')->table('t5000')->without('id')->run($this->conn);
     $i = 0;
     foreach ($cursor as $val) {
         if (!$this->compareArrays($doc, $val)) {
             echo "Read wrong value.\n";
         }
         if ($i++ >= 100) {
             break;
         }
     }
     unset($cursor);
     // Test 2: Call the cursor's close() method. The cursor should not return any more rows.
     $cursor = r\db('Huge')->table('t5000')->without('id')->run($this->conn);
     $cursor->close();
     if (!$this->compareArrays(array(), $cursor->toArray())) {
         echo "Cursor still returned results after it was closed.\n";
     }
     // Test 3: Retrieve all results. This tests paging.
     $this->checkQueryResult(r\db('Huge')->table('t5000')->without('id'), $docs);
 }
开发者ID:simensen,项目名称:php-rql,代码行数:26,代码来源:CursorTest.php

示例6: getLevelPaths

 /**
  * @param int $level
  * @return string[]
  */
 private function getLevelPaths($level)
 {
     if ($level) {
         return array_fill(0, $level, '..');
     }
     return array();
 }
开发者ID:raphhh,项目名称:pumpkin,代码行数:11,代码来源:PathFinder.php

示例7: create

 public function create()
 {
     $key = $this->getPrimary();
     //if it does exists, then update, else insert
     if ($this->exists()) {
         $this->update();
         return $this->{$key};
     } else {
         #####################################
         $columnstmp = $this->getColumns();
         foreach ($columnstmp as $colname) {
             $columns[$colname] = $this->{$colname};
         }
         $table = $this->getTable();
         $qmarks = array_fill(0, count($columns), '?');
         $sql = "INSERT INTO {$table} (" . join(',', array_keys($columns)) . ") VALUES(" . join(',', $qmarks) . ")";
         $columns = array_values($columns);
         //values must be integer indexed array
         $database = SomeFactory::getDBO();
         $statement = $database->prepare($sql);
         $this->sql = $sql;
         $success = $statement->execute($columns);
         ob_start();
         print_r($columns);
         $this->columnsdebug = ob_get_clean();
         return $this->{$key};
         #####################################
     }
 }
开发者ID:EmmiSiitonen,项目名称:Hops-palvelu,代码行数:29,代码来源:session.php

示例8: doBuildQuery

 /**
  * Builds a Doctrine query with processed values
  * 
  * @param   array   $values Values
  * @return  Doctrine_Query
  * @author  relo_san
  * @since   february 17, 2010
  */
 protected function doBuildQuery(array $values)
 {
     $query = isset($this->options['query']) ? clone $this->options['query'] : $this->getTable()->createQuery('r');
     if ($method = $this->getTableMethod()) {
         $query = $this->getTable()->{$method}($query);
     }
     $fields = $this->getFields();
     $names = array_merge($fields, array_diff(array_keys($this->validatorSchema->getFields()), array_keys($fields)));
     $fields = array_merge($fields, array_combine($names, array_fill(0, count($names), null)));
     foreach ($fields as $field => $type) {
         if (!isset($values[$field]) || null === $values[$field] || '' === $values[$field]) {
             continue;
         }
         $method = sprintf('add%sColumnQuery', self::camelize($this->getFieldName($field)));
         if (method_exists($this, $method)) {
             $this->{$method}($query, $field, $values[$field]);
         } else {
             if (null !== $type) {
                 if (!method_exists($this, $method = sprintf('add%sQuery', $type))) {
                     throw new LogicException(sprintf('Unable to filter for the "%s" type.', $type));
                 }
                 $this->{$method}($query, $field, $values[$field]);
             }
         }
     }
     return $query;
 }
开发者ID:relo-san,项目名称:dinDoctrineExtraPlugin,代码行数:35,代码来源:dinFormFilterDoctrine.php

示例9: _getInsertRowSQL

 /**
  * {@inheritdoc}
  *
  * @override
  * @internal Order of the parameters must be the same as the order of the columns in
  *           _getInsertRowSql.
  */
 protected function _getInsertRowSQL(PersistentCollection $coll)
 {
     $mapping = $coll->getMapping();
     $joinTable = $mapping['joinTable'];
     $columns = $mapping['joinTableColumns'];
     return 'INSERT INTO ' . $joinTable['name'] . ' (' . implode(', ', $columns) . ')' . ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')';
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:14,代码来源:ManyToManyPersister.php

示例10: _build_where_clause

 private function _build_where_clause($query)
 {
     if (!$query->where) {
         return;
     }
     $where = $where_params = [];
     $param_count = 0;
     foreach ($query->where as $condition) {
         # Case: ["foo" => $foo, "bar" => $bar];
         if (is_array($condition)) {
             foreach ($condition as $column => $value) {
                 $where[] = '`' . $column . '` = ?';
                 $where_params[] = $value;
             }
         } else {
             if ($count = substr_count($condition, '?')) {
                 foreach (range(0, $count - 1) as $i) {
                     if (!isset($query->where_params[$param_count])) {
                         throw new Exception\RuntimeException(sprintf("Value for question mark placeholder for WHERE clause part wasn't found (%s)", $condition));
                     }
                     if (is_array($query->where_params[$param_count])) {
                         $condition = preg_replace('/\\?/', implode(', ', array_fill(0, count($query->where_params[$param_count]), '?')), $condition, 1);
                     }
                     $where_params[] = $query->where_params[$param_count];
                     $param_count++;
                 }
             } elseif ($count = substr_count($condition, ':')) {
                 $where_params = $query->where_params;
             }
             $where[] = $condition;
         }
     }
     return [implode(' AND ', $where), $where_params];
 }
开发者ID:railsphp,项目名称:railsphp,代码行数:34,代码来源:QueryBuilder.php

示例11: combineArrayWithSingleElement

 public static function combineArrayWithSingleElement($keys, $var)
 {
     if (empty($keys)) {
         return array();
     }
     return array_combine($keys, array_fill(0, count($keys), $var));
 }
开发者ID:bergi9,项目名称:2Moons,代码行数:7,代码来源:ArrayUtil.class.php

示例12: get

 public function get($key)
 {
     $sql = 'SELECT k_key, k_value FROM ' . $this->_connection->prefixTable($this->table) . ' WHERE k_expire > \'' . date('Y-m-d H:i:s') . '\' AND k_key ';
     if (is_array($key)) {
         $in = '';
         foreach ($key as $k) {
             $in .= ',' . $this->_connection->quote($k);
         }
         $sql .= ' IN (' . substr($in, 1) . ')';
         $result = array_combine($key, array_fill(0, count($key), null));
         $rs = $this->_connection->query($sql);
         if (!$rs) {
             return $result;
         }
         foreach ($rs as $rec) {
             $result[$rec->k_key] = unserialize($rs->unescapeBin($rec->k_value));
         }
         return $result;
     } else {
         $sql .= ' = ' . $this->_connection->quote($key);
         $rs = $this->_connection->query($sql);
         if (!$rs) {
             return null;
         }
         $result = $rs->fetch();
         if (!$result) {
             return null;
         }
         return unserialize($rs->unescapeBin($result->k_value));
     }
 }
开发者ID:hadrienl,项目名称:jelix,代码行数:31,代码来源:db.kvdriver.php

示例13: test_getWordSets

 public function test_getWordSets()
 {
     // given an array of arrays like
     // array( array('a','b'), array('c','d') )
     // returns a summary as string: '(a|b),(c|d)'
     function serialize_sets($aSets)
     {
         $aParts = array();
         foreach ($aSets as $aSet) {
             $aParts[] = '(' . join('|', $aSet) . ')';
         }
         return join(',', $aParts);
     }
     $this->assertEquals(array(array('')), getWordSets(array(), 0));
     $this->assertEquals('(a)', serialize_sets(getWordSets(array("a"), 0)));
     $this->assertEquals('(a b),(a|b)', serialize_sets(getWordSets(array('a', 'b'), 0)));
     $this->assertEquals('(a b c),(a|b c),(a|b|c),(a b|c)', serialize_sets(getWordSets(array('a', 'b', 'c'), 0)));
     $this->assertEquals('(a b c d),(a|b c d),(a|b|c d),(a|b|c|d),(a|b c|d),(a b|c d),(a b|c|d),(a b c|d)', serialize_sets(getWordSets(array('a', 'b', 'c', 'd'), 0)));
     // Inverse
     $this->assertEquals('(a b c),(c|a b),(c|b|a),(b c|a)', serialize_sets(getInverseWordSets(array('a', 'b', 'c'), 0)));
     // make sure we don't create too many sets
     // 4 words => 8 sets
     // 10 words => 511 sets
     // 15 words => 12911 sets
     // 18 words => 65536 sets
     // 20 words => 169766 sets
     // 22 words => 401930 sets
     // 28 words => 3505699 sets (needs more than 4GB via 'phpunit -d memory_limit=' to run)
     $this->assertEquals(8, count(getWordSets(array_fill(0, 4, 'a'), 0)));
     $this->assertEquals(65536, count(getWordSets(array_fill(0, 18, 'a'), 0)));
 }
开发者ID:physycom,项目名称:Nominatim,代码行数:31,代码来源:NominatimTest.php

示例14: replace

 public function replace($content, $replace = '*')
 {
     // 计算文本内容长度
     $cLength = mb_strlen($content, 'UTF-8');
     $words = array();
     // 对每个字符进行关键词检查
     for ($i = 0; $i < $cLength; $i++) {
         $words[] = mb_substr($content, $i, 1, 'UTF-8');
     }
     // 对每个字符进行关键词检查
     foreach ($words as $i => $word) {
         // 首字符是否在过滤关键词分类中存在
         if (isset($this->classArr[$word])) {
             // 如果存在则将该分类下的所有关键词遍历,依次对文本内容中与每一个关键词位置长度相对应的字符串进行比较
             foreach ($this->classArr[$word] as $v) {
                 // 过滤关键词长度
                 $filterWordLength = mb_strlen($v, 'UTF-8');
                 // 获取文本中对应位置,相同长度的字符串
                 $contentEqPostionWord = mb_substr($content, $i, $filterWordLength, 'UTF-8');
                 // 对两个字符串进行比较
                 if ($contentEqPostionWord == $v) {
                     // 如果相同,则将该段字符串替换成相应长度的 *
                     array_splice($words, $i, $filterWordLength, array_fill(0, $filterWordLength, $replace));
                 }
             }
         }
     }
     return implode('', $words);
 }
开发者ID:emilymwang8,项目名称:ajk-broker,代码行数:29,代码来源:FilterWords.php

示例15: Calculate

 public function Calculate($str1, $str2)
 {
     $this->str1 = $str1;
     $this->str2 = $str2;
     $this->c = array_fill(0, strlen($str1), array_fill(0, strlen($str2), array()));
     $this->b = array_fill(0, strlen($str2), array_fill(0, strlen($str2), array()));
     $this->commonString = '';
     $this->length = 0;
     $str1_len = strlen($this->str1);
     $str2_len = strlen($this->str2);
     for ($i = 1; $i <= $str1_len; $i++) {
         $this->c[$i][0] = 0;
     }
     for ($j = 0; $j <= $str2_len; $j++) {
         $this->c[0][$j] = 0;
     }
     for ($i = 1; $i <= $str1_len; $i++) {
         for ($j = 1; $j <= $str2_len; $j++) {
             if (substr($this->str1, $i, 1) == substr($this->str2, $j, 1)) {
                 $this->c[$i][$j] = $this->c[$i - 1][$j - 1] + 1;
                 $this->b[$i][$j] = 'TOP_LEFT';
             } else {
                 $this->c[$i][$j] = $this->c[$i - 1][$j] >= $this->c[$i][$j - 1] ? $this->c[$i - 1][$j] : $this->c[$i][$j - 1];
                 $this->b[$i][$j] = $this->c[$i - 1][$j] >= $this->c[$i][$j - 1] ? 'TOP' : 'LEFT';
             }
         }
     }
     $this->generateCommonString(strlen($this->str1), strlen($this->str2));
     $this->length = strlen($this->commonString);
 }
开发者ID:aleen42,项目名称:LCS_PHP,代码行数:30,代码来源:LCS.php


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