本文整理汇总了PHP中util::array_first方法的典型用法代码示例。如果您正苦于以下问题:PHP util::array_first方法的具体用法?PHP util::array_first怎么用?PHP util::array_first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util
的用法示例。
在下文中一共展示了util::array_first方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: menu
/**
* Output a menu..
*
*/
public function menu(Twig_Environment $env, $identifier = "")
{
global $app;
$menus = $app['config']['menu'];
if (!empty($identifier) && isset($menus[$identifier])) {
$name = strtolower($identifier);
$menu = $menus[$identifier];
} else {
$name = strtolower(util::array_first_key($menus));
$menu = util::array_first($menus);
}
foreach ($menu as $key => $item) {
$menu[$key] = $this->menu_helper($item);
if (isset($item['submenu'])) {
foreach ($item['submenu'] as $subkey => $subitem) {
$menu[$key]['submenu'][$subkey] = $this->menu_helper($subitem);
}
}
}
// echo "<pre>\n" . util::var_dump($menu, true) . "</pre>\n";
echo $env->render('_sub_menu.twig', array('name' => $name, 'menu' => $menu));
}
示例2: getContent
//.........这里部分代码省略.........
if ($contenttype['singular_slug'] == $contenttypeslug || isset($parameters['returnsingle'])) {
$returnsingle = true;
}
$tablename = $this->prefix . $contenttype['slug'];
// for all the non-reserved parameters that are fields, we assume people want to do a 'where'
foreach ($parameters as $key => $value) {
if (in_array($key, array('order', 'where', 'limit', 'offset'))) {
continue;
// Skip this one..
}
if (!in_array($key, $this->getContentTypeFields($contenttype['slug'])) && !in_array($key, array("id", "slug", "datecreated", "datechanged", "username", "status"))) {
continue;
// Also skip if 'key' isn't a field in the contenttype.
}
$where[] = $this->parseWhereParameter($key, $value);
}
// If we need to filter, add the WHERE for that.
// InnoDB doesn't support full text search. WTF is up with that shit?
if (!empty($parameters['filter'])) {
$filter = safeString($parameters['filter']);
$filter_where = array();
foreach ($contenttype['fields'] as $key => $value) {
if (in_array($value['type'], array('text', 'textarea', 'html'))) {
$filter_where[] = sprintf("`%s` LIKE '%%%s%%'", $key, $filter);
}
}
if (!empty($filter_where)) {
$where[] = "(" . implode(" OR ", $filter_where) . ")";
}
}
$queryparams = "";
// implode 'where'
if (!empty($where)) {
$queryparams .= " WHERE (" . implode(" AND ", $where) . ")";
}
// Order
if (!empty($parameters['order'])) {
$order = safeString($parameters['order']);
if ($order[0] == "-") {
$order = substr($order, 1) . " DESC";
}
$queryparams .= " ORDER BY " . $order;
}
// Make the query for the pager..
$pagerquery = "SELECT COUNT(*) AS count FROM {$tablename}" . $queryparams;
// Add the limit
$queryparams .= sprintf(" LIMIT %s, %s;", ($page - 1) * $limit, $limit);
// Make the query to get the results..
$query = "SELECT * FROM {$tablename}" . $queryparams;
if (!$returnsingle) {
// echo "<pre>" . util::var_dump($query, true) . "</pre>";
}
$rows = $this->db->fetchAll($query);
// Make sure content is set, and all content has information about its contenttype
$content = array();
foreach ($rows as $key => $value) {
$content[$value['id']] = new Content($value, $contenttype);
}
// Make sure all content has their taxonomies
$this->getTaxonomy($content);
// Iterate over the contenttype's taxonomy, check if there's one we can use for grouping.
// If so, iterate over the content, and set ['grouping'] for each unit of content.
// But only if we're not sorting manually (i.e. have a ?order=.. parameter or $parameter['order'] )
if (empty($_GET['order']) && empty($parameters['order']) || $contenttype['sort'] == $parameters['order']) {
$have_grouping = false;
$taxonomy = $this->getContentTypeTaxonomy($contenttypeslug);
foreach ($taxonomy as $taxokey => $taxo) {
if ($taxo['behaves_like'] == "grouping") {
$have_grouping = true;
break;
}
}
if ($have_grouping) {
uasort($content, function ($a, $b) {
if ($a->group == $b->group) {
return 0;
}
return $a->group < $b->group ? -1 : 1;
});
}
}
if (!$returnsingle) {
// Set up the $pager array with relevant values..
$rowcount = $this->db->executeQuery($pagerquery)->fetch();
$pager = array('for' => $contenttypeslug, 'count' => $rowcount['count'], 'totalpages' => ceil($rowcount['count'] / $limit), 'current' => $page, 'showing_from' => ($page - 1) * $limit + 1, 'showing_to' => ($page - 1) * $limit + count($content));
$GLOBALS['pager'][$contenttypeslug] = $pager;
}
// If we requested a singular item..
if ($returnsingle) {
if (util::array_first_key($content)) {
return util::array_first($content);
} else {
$msg = sprintf("Storage: requested specific single content '%s%s%s', not found.", $contenttypeslug, isset($match[2]) ? "/" . $match[2] : "", isset($match[3]) ? "/" . $match[3] : "");
$app['log']->add($msg);
return false;
}
} else {
return $content;
}
}
示例3: test_array_first
public function test_array_first()
{
$test = array('a' => array('a', 'b', 'c'));
$this->assertEquals('a', util::array_first(util::array_get($test, 'a')));
}