本文整理汇总了PHP中array_find函数的典型用法代码示例。如果您正苦于以下问题:PHP array_find函数的具体用法?PHP array_find怎么用?PHP array_find使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_find函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_output
function parse_output($output, $strkey)
{
$key = array_find($strkey, $output);
if ($key !== false) {
return substr($output[$key], 20);
} else {
return false;
}
}
示例2: testFindFailure
public function testFindFailure()
{
// arrange
$array = array(array('id' => 1, 'name' => 'foo'), array('id' => 2, 'name' => 'bar'), array('id' => 3, 'name' => 'baz '), array('id' => 4, 'name' => 'bar'));
// act
$result = array_find($array, function ($item) {
return $item['name'] == 'qux';
});
// assert
$this->assertNull($result);
}
示例3: __construct
/**
* コンストラクタ。
* コンシューマキー、及びコンシューマ秘密鍵はプロパティファイルに定義することも可能です。
*
* config/global_properties.yml の設定例:
* <code>
* twitter:
* # コンシューマキー。
* consumerKey:
*
* # コンシューマ秘密鍵。
* consumerSecret:
* </code>
* @see Mars_OAuthProvider::__construct()
* @author Naomichi Yamakita <yamakita@dtx.co.jp>
*/
protected function __construct($consumerKey = NULL, $consumerSecret = NULL)
{
$config = Mars_Config::loadProperties('twitter');
if ($consumerKey === NULL) {
$consumerKey = array_find($config, 'consumerKey');
}
if ($consumerSecret === NULL) {
$consumerSecret = array_find($config, 'consumerSecret');
}
parent::__construct($consumerKey, $consumerSecret);
}
示例4: __construct
/**
* コンストラクタ。
* コンシューマキー、及びコンシューマ秘密鍵はプロパティファイルに定義することも可能です。
*
* config/global_properties.yml の設定例:
* <code>
* mixiGraph:
* # コンシューマキー。
* consumerKey:
*
* # コンシューマ秘密鍵。
* consumerSecret:
* </code>
* @see Mars_OAuthProvider::__construct()
* @author Naomichi Yamakita <yamakita@dtx.co.jp>
*/
protected function __construct($consumerKey = NULL, $consumerSecret = NULL)
{
$config = Mars_Config::loadProperties('mixiGraph');
if ($consumerKey === NULL) {
$consumerKey = array_find($config, 'consumerKey');
}
if ($consumerSecret === NULL) {
$consumerSecret = array_find($config, 'consumerSecret');
}
$this->_userAgent = $this->request->getUserAgent();
parent::__construct($consumerKey, $consumerSecret);
}
示例5: __construct
/**
* コンストラクタ。
* コンシューマキー、及びコンシューマ秘密鍵はコンストラクタの引数、またはプロパティファイルに定義することが可能です。
* (プロパティファイルの設定例は {@link Mars_MixiMobileApp} クラスの API を参照)
*
* @param string $consumerKey コンシューマキー。
* @param string $consumerSecret コンシューマ秘密鍵。
* @author Naomichi Yamakita <yamakita@dtx.co.jp>
*/
protected function __construct($consumerKey = NULL, $consumerSecret = NULL)
{
$config = Mars_Config::loadProperties('mixi');
if ($consumerKey === NULL) {
$consumerKey = array_find($config, 'consumerKey');
}
if ($consumerSecret === NULL) {
$consumerSecret = array_find($config, 'consumerSecret');
}
parent::__construct($consumerKey, $consumerSecret);
$this->_consumer = new OAuthConsumer($consumerKey, $consumerSecret);
$this->_hasZlib = extension_loaded('zlib');
}
示例6: getFormData
/**
* Fetch common form data needed for subclass controllers
* The 2 main items are the organization list participating in the specified CTA
* and the specified church (either passed in URI or set in cookie by WP site)
*
* @return Array
*/
protected function getFormData($permalink = null, $withs = [])
{
$orgs = $this->getOrgsForDropdown($withs);
\Log::debug('------------ QUERIES --------------');
\Log::debug(print_r(\DB::getQueryLog(), true));
// pass in the church to override, fall back to the cookie if it exists
$churchId = 0;
$churchUid = '';
if ($permalink === null) {
// RT - cannot use Laravel Cookie b/c it's expecting encrypted junk
$permalink = array_key_exists('church', $_COOKIE) ? $_COOKIE['church'] : null;
if (empty($permalink)) {
$permalink = null;
}
// just in case empty string
}
if ($permalink !== null) {
$church = array_find($orgs, function ($o) use($permalink) {
return $o->permalink == $permalink;
});
if ($church) {
$churchId = $church->id;
$churchUid = $church->uid;
}
}
$orgs4dropdown = ['0' => '-- Select Your Church --'];
foreach ($orgs as $o) {
$location = '';
if (!empty($o->effective_meeting_city)) {
$location = $o->effective_meeting_city;
}
if (!empty(trim($o->effective_meeting_country)) && ($o->effective_meeting_country != 'US' && $o->effective_meeting_country != 'CA')) {
$location .= ", " . $o->full_effective_meeting_country;
} else {
if (trim($o->effective_meeting_state)) {
$location .= ", " . $o->effective_meeting_state;
}
}
if (!empty(trim($location))) {
$location = ": " . $location;
}
$orgs4dropdown[$o->id] = $o->name . $location;
$o->dropdownLabel = $o->name . $location;
}
$orgs4dropdown[null] = 'Other';
return ['organizations' => $orgs, 'orgsDropdown' => $orgs4dropdown, 'churchId' => $churchId, 'churchUid' => $churchUid, 'permalink' => $permalink];
}
示例7: execute
public function execute()
{
$arguments = $this->controller->getArguments();
$type = array_find($arguments, 'type', 'json');
$level = array_find($arguments, 'level', 'error');
$levels = array('trace', 'debug', 'info', 'warning', 'error', 'fatal');
if (!in_array($level, $levels)) {
fputs(STDERR, sprintf('Invalid parameter [--level=%s]', $level));
exit;
}
$fp = fopen('php://stderr', 'r');
$buffer = NULL;
$data = fread($fp, 4096);
if ($type === 'json') {
$separate = str_repeat('=', 74);
$message = sprintf("%s\nSummary:\n%s\n%s\n" . "%s\n\$_SERVER:\n%s\n%s\n", $separate, $separate, json_string_format($data), $separate, $separate, var_export($_SERVER, TRUE));
}
$array = json_decode($data, TRUE);
$logger = Mars_Logger::getLogger(basename($array['path']));
$logger->{$level}($message);
}
示例8: array
"contact" => "author_data", # in author_data
);
$authorDataOrderBy = array(
"affiliation" => "affiliation",
"contact" => "name",
);
if(isset($_REQUEST["sort"])) {
$orderKey = $_REQUEST["sort"];
if(!array_key_exists($orderKey, $orderBy)) {
# Invalid order key
$orderKey = null;
}
}
if(empty($orderKey)) $orderKey = "date";
$orderColumn = $orderBy[$orderKey];
if(!array_find($orderColumn, $cols, false, true)) {
$cols[] = $orderColumn;
}
$list = $db->getQueryResults($search, $cols, 'AND', true, true, $orderColumn);
$html = '';
$i = 0;
$count = sizeof($list);
$max = 25;
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
if ($page > 1) {
$multiplier = $page - 1;
$skip = $multiplier * $max;
#echo "<!-- Skipping $skip on page $page with multiplier $multiplier for max $max for total results $count -->";
} else {
$skip = 0;
}
示例9: editAccess
function editAccess($link, $deltas)
{
/***
*
***/
global $db, $login_status, $default_user_database, $default_sql_user, $default_sql_password, $sql_url, $default_user_table, $db_cols;
try {
$udb = new DBHelper($default_user_database, $default_sql_user, $default_sql_password, $sql_url, $default_user_table, $db_cols);
$uid = $login_status['detail']['uid'];
$pid = $db->sanitize($link);
if (!$db->isEntry($pid, 'project_id', true)) {
return array('status' => false, 'error' => 'INVALID_PROJECT', 'human_error' => 'No project #' . $pid . ' exists');
}
$search = array('project_id' => $pid);
$projectList = $db->getQueryResults($search, '*', 'AND', false, true);
$project = $projectList[0];
$originalAccess = $project['access_data'];
$authorizedStatus = checkProjectAuthorized($project, $uid);
if (!$authorizedStatus['can_edit']) {
return array('status' => false, 'error' => 'UNAUTHORIZED', 'human_error' => 'You have insufficient privileges to change user permissions on project #' . $pid);
}
if (!is_array($deltas)) {
return array('status' => false, 'error' => 'BAD_DELTAS', 'human_error' => 'Your permission changes were malformed. Please correct them and try again.');
}
$additions = $deltas['add'];
$removals = $deltas['delete'];
$changes = $deltas['changes'];
$editList = $authorizedStatus['editors'];
$viewList = $authorizedStatus['viewers'];
$authorList = array($project['author']);
$totalList = array_merge($editList, $viewList, $authorList);
$notices = array();
$operations = array();
# Add users
foreach ($additions as $newUid) {
if (!$udb->isEntry($newUid, 'dblink')) {
$notices[] = 'User ' . $user['uid'] . " doesn't exist";
continue;
}
if (in_array($newUid, $totalList)) {
$notices[] = "{$newUid} is already given project permissions";
continue;
}
$viewList[] = $newUid;
$operations[] = "Succesfully added {$newUid} as a viewer";
}
# Remove users
foreach ($removals as $user) {
# Remove user from list after looping through each
if (!is_array($user)) {
$notices[] = "Couldn't remove user, permissions object malformed";
continue;
}
if (!$udb->isEntry($user['uid'], 'dblink')) {
$notices[] = 'User ' . $user['uid'] . " doesn't exist";
continue;
}
$currentRole = strtolower($user['currentRole']);
if ($currentRole == 'edit') {
$observeList = 'editList';
} elseif ($currentRole == 'read') {
$observeList = 'viewList';
} elseif ($currentRole == 'authorList') {
# Check the lists for other author thing
$observeList = 'authorList';
continue;
} else {
$notices[] = "Unrecognized current role '" . strotupper($currentRole) . "'";
continue;
}
$key = array_find($user['uid'], ${$observeList});
if ($key === false) {
$notices[] = 'Invalid current role for ' . $user['uid'];
continue;
}
$orig = ${$observeList};
unset(${$observeList}[$key]);
$operations[] = 'User ' . $user['uid'] . " removed from role '" . strtoupper($currentRole) . "' in " . $observeList;
}
# Changes to existing users
foreach ($changes as $user) {
if (!is_array($user)) {
$notices[] = "Couldn't change permissions, permissions object malformed";
continue;
}
if (!$udb->isEntry($user['uid'], 'dblink')) {
$notices[] = 'User ' . $user['uid'] . " doesn't exist";
continue;
}
if (empty($user['currentRole']) || empty($user['newRole']) || empty($user['uid'])) {
$notices[] = "Couldn't change permissions, missing one of newRole, uid, or currentRole for user";
continue;
}
# Match the roles
$newRole = strtolower($user['newRole']);
$currentRole = strtolower($user['currentRole']);
if ($newRole == $currentRole) {
$notices[] = 'User ' . $user['uid'] . " already has permissions '" . strtoupper($currentRole) . "'";
continue;
}
//.........这里部分代码省略.........
示例10: array
<?php
}
?>
</results>
<?php
} else {
if ($_REQUEST['type'] == 'friends') {
$matchedusers = array();
$searcharray = array();
$userpros = array();
foreach ($_SESSION['friends'] as $user) {
$userpro = getminipro($user);
$searcharray[$user] = $userpro['username'];
$userpros[$user] = $userpro;
}
$matchedusers = array_find($_REQUEST['key'], $searcharray);
?>
<users> <?php
foreach ($matchedusers as $user) {
$userpro = $userpros[$user];
?>
<user>
<userid><?php
echo $userpro['userid'];
?>
</userid>
<username><?php
echo $userpro['username'];
?>
</username>
<propic><?php
示例11: update_combat
function update_combat($planet_id = 0, $update_to = '')
{
$this->log[] = 'Update Combat';
if (empty($update_to)) {
$update_to = $this->data->update_to();
}
// ##################################################
// Make sure any navy groups prior to now have landed {
if (empty($planet_id)) {
$this->sql->where(array(array('tasks', 'round_id', $_SESSION['round_id']), array('tasks', 'type', TASK_NAVY), array('tasks', 'completion', $update_to, '<=')));
$this->sql->orderby(array(array('tasks', 'planet_id', 'asc'), array('tasks', 'completion', 'asc')));
$this->sql->limit(1);
$db_result = $this->sql->execute();
while ($db_row = mysql_fetch_array($db_result, MYSQL_ASSOC)) {
$this->data->updater->task_navy($db_row);
}
}
// }
list($combat, $info, $blueprints) = $this->getAllInformation($planet_id, $update_to);
if (empty($combat)) {
return;
}
// ##################################################
// Loop through all combat {
foreach ($combat as $planet_id => $current) {
$this->log[] = 'Combat: Updating ' . $planet_id;
$reports = array();
$last_update = $update_to - $current['combat']['completion'];
$time_left = $last_update % $info['round']['combattick'];
$combat_updates = floor($last_update / $info['round']['combattick']) + 1;
// ##################################################
// Update however many times combat happened in this time {
for ($i = 0; $i < $combat_updates; $i++) {
// Start running combat
$this->log[] = 'Combat: Update ' . $i;
$combat_report = array();
$current['combat']['rounds']++;
// If no kingdoms are present no battle.
$fighting = false;
$kingdoms = array_keys($current['sudo']['army']['kingdoms'] + $current['sudo']['navy']['kingdoms'] + array($info['planets'][$planet_id]['kingdom_id'] => true));
foreach ($kingdoms as $kingdom_id) {
$variable = array_diff($kingdoms, array_keys($info['kingdoms'][$kingdom_id]['allies']) + array($kingdom_id));
if (!empty($variable)) {
$fighting = true;
break;
}
}
if (!$fighting) {
// nobody won
// delete combat
$db_query = "DELETE FROM `combat` WHERE `combat_id` = '" . $current['combat']['combat_id'] . "' LIMIT 1";
$db_result = mysql_query($db_query);
$this->log[] = 'Combat: No combat';
// go to the next planet for combat
continue 2;
}
$after_combat = $current;
// Repeat for army and navy units
foreach ($this->type_array as $type) {
$this->log[] = 'Combat: Type: ' . $type;
$storedCombatDamage = array();
foreach ($current['sudo'][$type]['kingdoms'] as $kingdom_id => $groups) {
$kingdom = $info['kingdoms'][$kingdom_id];
$this->log[] = 'Combat: Kingdom: ' . $kingdom_id;
$find = array('kingdom_id' => array_keys($kingdom['allies']));
$find['kingdom_id'][] = $kingdom_id;
foreach ($groups as $group_id => $units) {
$group = $info['groups'][$type][$group_id];
$this->log[] = 'Combat: Group: ' . $group_id;
foreach ($units as $unit_id => $unit_count) {
$unit = $blueprints[$type][$unit_id];
$this->log[] = 'Combat: Unit: ' . $unit_id;
foreach ($unit['weapons'] as $weapon_id => $weapon_count) {
$weapon = $blueprints['weapon'][$weapon_id];
$this->log[] = 'Combat: Weapon: ' . $weapon_id;
// Filter remaining groups against kingdom allies
$targets['groups'] = array_find($find, $after_combat['sudo'][$type]['groups'], true);
if (empty($targets['groups'])) {
$this->log[] = 'Combat: Empty Targets';
// This kingdom is out of targets
// Continue with the next kingdom
continue 4;
}
// Rate of Fire Spray: Weapons with a high rof should have decreased accuracy.
$rof_spray = pow($weapon['rateoffire'], 0.9) / $weapon['rateoffire'];
$ammo = $unit_count * $weapon_count * $weapon['rateoffire'] * $weapon['accuracy'] * $rof_spray / 100;
$this->log[] = 'Combat: Ammo: ' . $ammo;
$targets_left = true;
if (isset($targeted)) {
unset($targeted);
}
// Repeat combat until we're out of targets or ammo
while ($ammo > 0 && $targets_left) {
$targets['groups'] = array_find($find, $after_combat['sudo'][$type]['groups'], true);
if (!empty($group['targets'][$weapon_id]) && empty($targeted['group'])) {
$target_type = $group['targets'][$weapon_id];
$targeted['group'] = true;
$this->log[] = 'Combat: Target: Group: ' . $target_type;
} elseif (!empty($weapon['targets'][$weapon_id]) && empty($targeted['weapon'])) {
$target_type = $weapon['targets'][$weapon_id];
//.........这里部分代码省略.........
示例12: foreach
foreach ($filelist as &$v) {
if (isset($_SESSION['list'][$v['fid']])) {
if ($_SESSION['list'][$v['fid']]['filename'] != $v['name']) {
$fix->execute(array($v['name'], $v['fid'], $_SESSION['user_id']));
$check_result = '<td><font color="orange">数据库中的文件名错误,已经被自动修正。</font></td>';
} else {
$check_result = '<td><font color="green">自动补档保护中</font></td>';
}
$_SESSION['filecheck'][$v['fid']] = false;
$check_result .= '<td><a href="' . $jumper . $_SESSION['list'][$v['fid']]['id'] . '" target="_blank">' . $jumper . $_SESSION['list'][$v['fid']]['id'] . '</a></td><td><a href="http://pan.baidu.com' . $_SESSION['list'][$v['fid']]['link'] . '">http://pan.baidu.com' . $_SESSION['list'][$v['fid']]['link'] . '</a></td>';
unset($_SESSION['list'][$v['fid']], $_SESSION['list_filenames'][$v['fid']]);
} else {
if (array_find($v['name'] . '/', $_SESSION['list_filenames']) !== false) {
$check_result = '<td colspan="3"><font color="blue">文件夹内的文件被加入自动补档</font></td>';
$_SESSION['filecheck'][$v['fid']] = false;
} elseif (array_find($v['name'], $_SESSION['list_filenames'], true) !== false) {
$check_result = '<td colspan="3"><font color="blue">父文件夹被加入自动补档</font></td>';
$_SESSION['filecheck'][$v['fid']] = false;
} else {
$check_result = '<td colspan="3">本文件未加入自动补档</td>';
$_SESSION['filecheck'][$v['fid']] = true;
}
}
if ($_SESSION['filecheck'][$v['fid']]) {
?>
<tr><td><form method="post" action="add.php"><input type="hidden" name="fid" value="<?php
echo $v['fid'];
?>
" /><input type="hidden" name="filename" value="<?php
echo $v['name'];
?>
示例13: __filter_user_object_content
/**
* This function filters the content array
* using it's details
*
* @global object $userquery
* @param string $group
* @param string $return
* @return array
*/
function __filter_user_object_content($_group = null, $return = false, $cache = false)
{
if ($this->__get_filtered_content() && $cache === false) {
return $this->__get_filtered_content();
}
$groups = $this->___groups();
$group = $_group ? $_group : get('object_group');
if (!$this->__get_current_user()) {
global $userquery;
$user = $userquery->get_user_details(get('user'), false, true);
$user = $this->__set_current_user($user);
} else {
$user = $this->__get_current_user();
}
if (!$user) {
return false;
}
if (!$group || !$groups[$group]) {
$group = key($groups);
}
if ($groups[$group]) {
foreach ($groups[$group] as $key => $value) {
$info = $this->__extract_key_details($key);
$section_disbaled = false;
$is_private = false;
$no_permission = false;
$section_disbaled = $this->_confirm_section_enabled($value, $info);
if (array_find('is_content', $info)) {
$is_private = $this->_confirm_private($value, $key);
$no_permission = $this->_confirm_permissions($value, $key);
} else {
foreach ($value as $type => $content) {
$content_pri = $this->_confirm_private($content, $type);
$content_per = $this->_confirm_permissions($content, $type);
if ($content_pri && $content_per) {
$remove_content[] = $content_pri;
$remove_content[] = $content_per;
} else {
if ($content_pri) {
$remove_content[] = $content_pri;
} else {
if ($content_per) {
$remove_content[] = $content_per;
}
}
}
}
}
if ($section_disbaled || $is_private || $no_permission) {
continue;
}
if (isset($remove_content)) {
foreach ($remove_content as $rc) {
if ($groups[$group][$key][$rc]) {
unset($groups[$group][$key][$rc]);
}
}
$value = $groups[$group][$key];
}
unset($remove_content);
if ($value) {
$filtered_content[$key] = $value;
}
}
return $return ? $filtered_content : $this->__set_filtered_content($filtered_content);
}
}
示例14: removeAddress
/**
* @inheritdoc
*/
public function removeAddress($address)
{
unset($this->addresses[array_find($address)]);
}
示例15: array_compare
function array_compare($tax_rates)
{
$after = array();
foreach ($tax_rates as $key => $val) {
$first_two = array("label" => $val['label'], "compound" => $val['compound'], 'rate' => $val['rate'], 'shipping' => $val['shipping'], 'is_all_states' => $val['is_all_states'], 'class' => $val['class']);
$found = array_find($first_two, $after);
if ($found !== false) {
$combined = $after[$found]["state"];
$combined2 = $after[$found]["country"];
$combined = !is_array($combined) ? array($combined) : $combined;
$combined2 = !is_array($combined2) ? array($combined2) : $combined2;
$after[$found] = array_merge($first_two, array("state" => array_merge($combined, array($val['state'])), "country" => array_merge($combined2, array($val['country']))));
} else {
$after = array_merge($after, array(array_merge($first_two, array("state" => $val['state'], "country" => $val['country']))));
}
}
return $after;
}