本文整理汇总了PHP中array_walk函数的典型用法代码示例。如果您正苦于以下问题:PHP array_walk函数的具体用法?PHP array_walk怎么用?PHP array_walk使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_walk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDownAfterClass
public static function tearDownAfterClass()
{
if (!self::$timing) {
echo "\n";
return;
}
$class = get_called_class();
echo "Timing results : {$class}\n";
$s = sprintf("%40s %6s %9s %9s %4s\n", 'name', 'count', 'total', 'avg', '% best');
echo str_repeat('=', strlen($s)) . "\n";
echo $s;
echo str_repeat('-', strlen($s)) . "\n";
array_walk(self::$timing, function (&$value, $key) {
$value['avg'] = round($value['total'] / $value['count'] * 1000000, 3);
});
usort(self::$timing, function ($a, $b) {
$at = $a['avg'];
$bt = $b['avg'];
return $at === $bt ? 0 : ($at < $bt ? -1 : 1);
});
$best = self::$timing[0]['avg'];
foreach (self::$timing as $timing) {
printf("%40s %6d %7.3fms %7.3fus %4.1f%%\n", $timing['name'], $timing['count'], round($timing['total'] * 1000, 3), $timing['avg'], round($timing['avg'] / $best * 100, 3));
}
echo str_repeat('-', strlen($s)) . "\n\n";
printf("\nTiming compensated for avg overhead for: timeIt of %.3fus and startTimer/endTimer of %.3fus per invocation\n\n", self::$timeItOverhead * 1000000, self::$startEndOverhead * 1000000);
parent::tearDownAfterClass();
}
示例2: __construct
function __construct($uid = NULL)
{
parent::__construct();
$this->table = 'user';
$this->fields = array_merge($this->fields, array('alias' => '', 'password' => ''));
if (is_null($uid)) {
$uid = $this->session->userdata('user/id');
}
if ($uid) {
$user = $this->fetch($uid);
$this->id = $uid;
$this->name = $user['name'];
$this->group = explode(',', $user['group']);
}
//TODO 生成了过多的查询,应予以优化
$this->teams = $this->team->trace($this->id);
//获取存在数据库中的用户配置项
$this->db->from('user_config')->where('user', $this->id);
$config = array_sub($this->db->get()->result_array(), 'value', 'name');
array_walk($config, function (&$value) {
$decoded = json_decode($value);
if (!is_null($decoded)) {
$value = $decoded;
}
});
$this->config->user = $config;
}
示例3: isQueryAllowed
/**
* Checks if query allowed.
*
* Perform testing if table exist for DROP TABLE query
* to avoid stoping execution while try to drop not existent table.
*
* @param ezcDbHandler $db
* @param string $query
*
* @return boolean false if query should not be executed.
*/
public function isQueryAllowed(ezcDbHandler $db, $query)
{
if (strstr($query, 'AUTO_INCREMENT')) {
return false;
}
if (substr($query, 0, 10) == 'DROP TABLE') {
$tableName = substr($query, strlen('DROP TABLE "'), -1);
// get table name without quotes
$result = $db->query("SELECT count( table_name ) AS count FROM user_tables WHERE table_name='{$tableName}'")->fetchAll();
if ($result[0]['count'] == 1) {
$sequences = $db->query("SELECT sequence_name FROM user_sequences")->fetchAll();
array_walk($sequences, create_function('&$item,$key', '$item = $item[0];'));
foreach ($sequences as $sequenceName) {
// try to drop sequences related to dropped table.
if (substr($sequenceName, 0, strlen($tableName)) == $tableName) {
$db->query("DROP SEQUENCE \"{$sequenceName}\"");
}
}
return true;
} else {
return false;
}
}
return true;
}
示例4: generateStatistics
/**
* Rank / sort items parsed from the log
*
* @see parseFile()
*/
public function generateStatistics()
{
if ($this->items === null) {
throw new \Exception('You have to parse a file first');
}
$this->statistics = ['hosts' => [], 'files' => []];
array_walk($this->items, function ($item) {
$url = parse_url($item->request);
$host = $url['host'];
$file = $host . $url['path'];
if (isset($this->statistics['hosts'][$host])) {
$this->statistics['hosts'][$host] += 1;
} else {
$this->statistics['hosts'][$host] = 1;
}
if ($item->requestMethod == 'GET' && strpos($url['path'], '.') !== false) {
if (isset($this->statistics['files'][$file])) {
$this->statistics['files'][$file] += 1;
} else {
$this->statistics['files'][$file] = 1;
}
}
});
arsort($this->statistics['files']);
arsort($this->statistics['hosts']);
}
示例5: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->databaseContents['content_node_field'] = array(array('field_name' => 'field_test_four', 'type' => 'number_float', 'global_settings' => 'a:0:{}', 'required' => '0', 'multiple' => '0', 'db_storage' => '1', 'module' => 'number', 'db_columns' => 'a:1:{s:5:"value";a:3:{s:4:"type";s:5:"float";s:8:"not null";b:0;s:8:"sortable";b:1;}}', 'active' => '1', 'locked' => '0'));
$this->databaseContents['content_node_field_instance'] = array(array('field_name' => 'field_test_four', 'type_name' => 'story', 'weight' => '3', 'label' => 'Float Field', 'widget_type' => 'number', 'widget_settings' => 'a:0:{}', 'display_settings' => 'a:0:{}', 'description' => 'An example float field.', 'widget_module' => 'number', 'widget_active' => '1'));
$this->databaseContents['content_type_story'] = array(array('nid' => 5, 'vid' => 5, 'uid' => 5, 'field_test_four_value' => '3.14159'));
$this->databaseContents['system'] = array(array('type' => 'module', 'name' => 'content', 'schema_version' => 6001, 'status' => TRUE));
foreach ($this->expectedResults as $k => $row) {
foreach (array('nid', 'vid', 'title', 'uid', 'body', 'teaser', 'format', 'timestamp', 'log') as $field) {
$this->databaseContents['node_revisions'][$k][$field] = $row[$field];
switch ($field) {
case 'nid':
case 'vid':
break;
case 'uid':
$this->databaseContents['node_revisions'][$k]['uid']++;
break;
default:
unset($row[$field]);
break;
}
}
$this->databaseContents['node'][$k] = $row;
}
array_walk($this->expectedResults, function (&$row) {
$row['node_uid'] = $row['uid'];
$row['revision_uid'] = $row['uid'] + 1;
unset($row['uid']);
});
parent::setUp();
}
示例6: __construct
function __construct($data)
{
$object = $this;
array_walk($data, function ($value, $key) use($object) {
$object->{$key} = $value;
});
}
示例7: __construct
/**
* Constructor
*
* @param array $elements
* @param ArrayCollection $received
* @param Basket $basket
* @param Boolean $flatten
*/
public function __construct(array $elements, ArrayCollection $received, Basket $basket = null, $flatten = self::FLATTEN_NO)
{
parent::__construct($elements);
$this->received = $received;
$this->basket = $basket;
$this->isSingleStory = $flatten !== self::FLATTEN_YES && 1 === count($this) && $this->first()->isStory();
if (self::FLATTEN_NO !== $flatten) {
$to_remove = [];
foreach ($this as $key => $record) {
if ($record->isStory()) {
if (self::FLATTEN_YES === $flatten) {
$to_remove[] = $key;
}
foreach ($record->get_children() as $child) {
$this->set($child->get_serialize_key(), $child);
}
}
}
foreach ($to_remove as $key) {
$this->remove($key);
}
}
$i = 0;
$records = $this->toArray();
array_walk($records, function ($record) use(&$i) {
$record->setNumber($i++);
});
}
示例8: cleanupTables
protected function cleanupTables()
{
switch ($this->db->getName()) {
case 'pgsql':
$tables = $this->db->query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")->fetchAll();
array_walk($tables, create_function('&$item,$key', '$item = $item[0];'));
foreach ($tables as $tableName) {
$this->db->query("DROP TABLE \"{$tableName}\"");
}
break;
case 'oracle':
$tables = $this->db->query("SELECT table_name FROM user_tables")->fetchAll();
array_walk($tables, create_function('&$item,$key', '$item = $item[0];'));
foreach ($tables as $tableName) {
$this->db->query("DROP TABLE \"{$tableName}\"");
}
$sequences = $this->db->query("SELECT sequence_name FROM user_sequences")->fetchAll();
array_walk($sequences, create_function('&$item,$key', '$item = $item[0];'));
foreach ($sequences as $sequenceName) {
$this->db->query("DROP SEQUENCE \"{$sequenceName}\"");
}
break;
default:
$this->db->exec('DROP TABLE IF EXISTS workflow;');
$this->db->exec('DROP TABLE IF EXISTS node;');
$this->db->exec('DROP TABLE IF EXISTS node_connection;');
$this->db->exec('DROP TABLE IF EXISTS variable_handler;');
$this->db->exec('DROP TABLE IF EXISTS execution;');
$this->db->exec('DROP TABLE IF EXISTS execution_state;');
}
}
示例9: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// check for maintenance mode - do not run cron jobs if it is switched on
if ($this->getContainer()->get('oro_platform.maintenance')->isOn()) {
$output->writeln('');
$output->writeln('<error>System is in maintenance mode, aborting</error>');
return;
}
$daemon = $this->getContainer()->get('oro_cron.job_daemon');
$skipCheckDaemon = $input->getOption('skipCheckDaemon');
// check if daemon is running
if (!$skipCheckDaemon && !$daemon->getPid()) {
$output->writeln('');
$output->write('Daemon process not found, running.. ');
if ($pid = $daemon->run()) {
$output->writeln(sprintf('<info>OK</info> (pid: %u)', $pid));
} else {
$output->writeln('<error>failed</error>. Cron jobs can\'t be launched.');
return;
}
}
$schedules = $this->getAllSchedules();
$em = $this->getEntityManager('JMSJobQueueBundle:Job');
$jobs = $this->processCommands($output, $this->getApplication()->all('oro:cron'), $schedules);
$jobs = array_merge($jobs, $this->processSchedules($output, $schedules));
array_walk($jobs, [$em, 'persist']);
$em->flush();
$output->writeln('');
$output->writeln('All commands finished');
}
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$database_contents = $this->expectedResults;
array_walk($this->expectedResults, function (&$row) {
$row['node_uid'] = $row['uid'];
$row['revision_uid'] = $row['uid'] + 1;
unset($row['uid']);
});
$database_contents[] = array('nid' => 5, 'vid' => 5, 'type' => 'article', 'language' => 'en', 'title' => 'node title 5', 'uid' => 1, 'status' => 1, 'timestamp' => 1279290908, 'created' => 1279290908, 'changed' => 1279308993, 'comment' => 0, 'promote' => 1, 'moderate' => 0, 'sticky' => 0, 'tnid' => 0, 'translate' => 0, 'body' => 'body for node 5', 'teaser' => 'body for node 5', 'format' => 1, 'log' => 'log message 3');
// Add another row with an article node and make sure it is not migrated.
foreach ($database_contents as $k => $row) {
foreach (array('nid', 'vid', 'title', 'uid', 'body', 'teaser', 'format', 'timestamp', 'log') as $field) {
$this->databaseContents['node_revisions'][$k][$field] = $row[$field];
switch ($field) {
case 'nid':
case 'vid':
break;
case 'uid':
$this->databaseContents['node_revisions'][$k]['uid']++;
break;
default:
unset($row[$field]);
break;
}
}
$this->databaseContents['node'][$k] = $row;
}
parent::setUp();
}
示例11: converio_image_slider
function converio_image_slider($atts, $content = '')
{
if (isset($atts) && !empty($atts)) {
array_walk($atts, 'converio_arrangement_shortcode_arr_value');
}
extract(shortcode_atts(array('type' => '', 'translate_next' => '', 'translate_previous' => ''), $atts));
remove_all_filters('converio_filters_image_slider', 10);
if ($type == '2') {
add_filter('converio_filters_image_slider', 'converio_filter_image_slider_two', 10);
$output = '<div class="slider-image">';
$output .= '<div class="container">';
$output .= '<p class="number"><span></span>/<b></b></p>';
$output .= '<ul id="slides">';
$output .= '<a class="slidesjs-previous slidesjs-navigation" href="#" title="Previous">' . $translate_next . '</a> <a class="slidesjs-next slidesjs-navigation" href="#" title="Next">' . $translate_previous . '</a>';
$output .= do_shortcode($content);
$output .= '</ul>';
$output .= '</div>';
$output .= '</div>';
} else {
add_filter('converio_filters_image_slider', 'converio_filter_image_slider_one', 10);
$output = '<section class="slider3">';
$output .= '<div class="slider">';
$output .= do_shortcode($content);
$output .= '</div>';
$output .= '</section>';
}
return $output;
}
示例12: render
/**
* Sets response body of appended data to be json_encoded
*
* @param int $status
* @param array|null $data
* @return void
*/
public function render($status = 200, $data = array())
{
$data = array_merge(array('status' => $status), $this->all(), is_array($data) ? $data : array());
if (isset($data['flash']) && is_object($data['flash'])) {
$flash = $this->data->flash->getMessages();
if (count($flash)) {
$data['flash'] = $flash;
} else {
unset($data['flash']);
}
}
// Nettoyage des accents des chaines de caractère à afficher
array_walk($data, function (&$value, $key) {
if (is_string($value)) {
$value = $this->ascii_to_entities($value);
}
});
$app = \Slim\Slim::getInstance();
$response = $app->response();
$response->status($status);
$response->header('Content-Encoding', 'UTF-8');
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Methods', '*');
$response->header('Content-Type', 'application/json;charset=UTF-8');
$response->body(html_entity_decode(json_encode($data, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT)));
}
示例13: in_array_i4
function in_array_i4($needle, $haystack, $strict = FALSE)
{
if (is_string($needle)) {
array_walk($haystack, 'arr_strtolower');
}
return in_array(strtolower($needle), $haystack, $strict);
}
示例14: __invoke
/**
* List the components
*
* @param Route $route
* @param Console $console
* @return int
*/
public function __invoke(Route $route, Console $console)
{
array_walk($this->components, function ($component) use($console) {
$console->writeLine($component);
});
return 0;
}
示例15: diff
/**
*/
function diff($from_lines, $to_lines)
{
array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
/* Convert the two input arrays into strings for xdiff processing. */
$from_string = implode("\n", $from_lines);
$to_string = implode("\n", $to_lines);
/* Diff the two strings and convert the result to an array. */
$diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
$diff = explode("\n", $diff);
/* Walk through the diff one line at a time. We build the $edits
* array of diff operations by reading the first character of the
* xdiff output (which is in the "unified diff" format).
*
* Note that we don't have enough information to detect "changed"
* lines using this approach, so we can't add Text_Diff_Op_changed
* instances to the $edits array. The result is still perfectly
* valid, albeit a little less descriptive and efficient. */
$edits = array();
foreach ($diff as $line) {
switch ($line[0]) {
case ' ':
$edits[] = new Text_Diff_Op_copy(array(substr($line, 1)));
break;
case '+':
$edits[] = new Text_Diff_Op_add(array(substr($line, 1)));
break;
case '-':
$edits[] = new Text_Diff_Op_delete(array(substr($line, 1)));
break;
}
}
return $edits;
}