function deep_in_array($value, $array, $case_insensitive = false) { foreach ($array as $item) { if (is_array($item)) { $ret = deep_in_array($value, $item, $case_insensitive); } else { $ret = $case_insensitive ? strtolower($item) == $value : $item == $value; } if ($ret) { return $ret; } } return false; }
function deep_in_array($search, $array) { foreach ($array as $value) { if (!is_array($value)) { if ($search === $value) { return true; } } else { if (deep_in_array($search, $value)) { return true; } } } return false; }
function deep_in_array($value, $array) { foreach ($array as $item) { if (!is_array($item)) { if ($item == $value) { return true; } else { continue; } } if (in_array($value, $item)) { return true; } else { if (deep_in_array($value, $item)) { return true; } } } return false; }
public function add($name, $class = 0, $race = 0, $lvl = 0, $note = '') { if ($race == 'Scourge' || $race == 'SCOURGE') { $race = 'Undead'; } if ($race == 'BloodElf' || $race == 'BLOODELF') { $race = 'Blood Elf'; } if ($race == 'NightElf' || $race == 'NIGHTELF') { $race = 'Night Elf'; } if ($class == 'DEATHKNIGHT' || $class == 'DeathKnight') { $class = 'Death Knight'; } if ($class == 'DRUID') { $class = 'Druid'; } if (!deep_in_array($name, $this->members)) { $this->members[] = array('name' => $name, 'class' => $class, 'race' => $race, 'level' => $lvl, 'note' => $note); } }
function get_active_friends($num = null, $size = null, $days = null) { $num = $num ? $num : 15; $size = $size ? $size : 34; $days = $days ? $days : 30; $array = array(); $comments = get_comments(array('status' => 'approve', 'author__not_in' => 1, 'date_query' => array('after' => $days . ' days ago'))); if (!empty($comments)) { foreach ($comments as $comment) { $email = $comment->comment_author_email; $author = $comment->comment_author; $url = $comment->comment_author_url; $data = human_time_diff(strtotime($comment->comment_date)); if ($email != "") { $index = deep_in_array($email, $array); if ($index > -1) { $array[$index]["number"] += 1; } else { array_push($array, array("email" => $email, "author" => $author, "url" => $url, "date" => $data, "number" => 1)); } } } foreach ($array as $k => $v) { $edition[] = $v['number']; } array_multisort($edition, SORT_DESC, $array); // 数组倒序排列 } $output = '<ul class="active-items">'; if (empty($array)) { $output = '<li>none data.</li>'; } else { $max = count($array) > $num ? $num : count($array); for ($o = 0; $o < $max; $o++) { $v = $array[$o]; $active_avatar = get_avatar($v["email"], $size); $active_url = $v["url"] ? $v["url"] : "javascript:;"; $active_alt = $v["author"] . ' - 共' . $v["number"] . ' 条评论,最后评论于' . $v["date"] . '前。'; $output .= '<li class="active-item" data-info="' . $active_alt . '"><a target="_blank" rel="external nofollow" href="' . $active_url . '">' . $active_avatar . '</a></li>'; } } $output .= '</ul>'; return $output; }
header('Location:.'); } function deep_in_array($value, $array) { foreach ($array as $item) { if (in_array($value, $item)) { return true; } else { contiune; } } return false; } if (isset($_POST['add'])) { try { if (!deep_in_array($_POST['no'], $results)) { $sql = 'INSERT INTO allcourse SET no = :no, name = :name, department = :department, major = :major, registered = :registered'; $s = $pdo->prepare($sql); $s->bindValue(':no', $_POST['no']); $s->bindValue(':name', $_POST['name']); $s->bindValue(':department', $_POST['department']); $s->bindValue(':major', $_POST['major']); $s->bindValue(':registered', 0); $s->execute(); } else { $sql = 'UPDATE allcourse SET
function select($fieldName, $options = array(), $selected = null, $attributes = array()) { $sel = ''; if (!is_null($selected) && $selected != '') { if (!is_array($selected)) { $selected = array(strtolower($selected)); } } else { if (isset($attributes['value'])) { if (!is_array($attributes['value'])) { $selected = array(strtolower($attributes['value'])); } else { $selected = $attributes['value']; } unset($attributes['value']); } } if (isset($attributes['multiple'])) { $select = sprintf($this->Html->tags['selectmultiplestart'], $fieldName, $this->_parseAttributes($attributes)); unset($attributes['multiple']); } else { $select = sprintf($this->Html->tags['selectstart'], $fieldName, $this->_parseAttributes($attributes)); } foreach ($options as $value => $text) { $disabled = false; $sel = ''; if (is_array($text) || is_object($text)) { $text = (array) $text; $disabled = Sanitize::getBool($text, 'disabled', false); if (!isset($text['text'])) { $text = current($text); } $value = isset($text['value']) ? $text['value'] : $value; $text = $text['text']; // For CMS db query results w/o having to do an additional foreach } $text = htmlspecialchars($text, ENT_QUOTES, 'utf-8', false); # Multiple select list if ($selected && is_array($selected)) { $sel = deep_in_array($value, $selected, true) ? ' selected="selected"' : ''; # Single select list } elseif ($selected) { $sel = $value == $selected ? ' selected="selected"' : ''; } $disabled and $sel .= ' disabled="disabled"'; $select .= sprintf($this->Html->tags['selectoption'], $value, $sel, $text); } $select .= $this->Html->tags['selectend']; return $select; }