本文整理汇总了PHP中array_where函数的典型用法代码示例。如果您正苦于以下问题:PHP array_where函数的具体用法?PHP array_where怎么用?PHP array_where使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_where函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dbeav_filter_parser
function dbeav_filter_parser($filter = array(), &$object)
{
if (!is_array($filter)) {
return $filter;
}
$tPre = '`' . $object->table_name(true) . '`' . '.';
$where = [1];
// 因为searchOptions 会员非 dbschme定义的字段
$qb = $object->database()->createQueryBuilder();
$cols = array_merge($object->searchOptions(), $object->_columns());
// 过滤无用的filter条件
$filter = array_where($filter, function ($filterKey, $filterValue) use($cols) {
return !is_null($filterValue) && (isset($cols[$filterKey]) || strpos($filterKey, '|'));
});
foreach ($filter as $filterKey => $filterValue) {
if (strpos($filterKey, '|')) {
list($columnName, $type) = explode('|', $filterKey);
$where[] = $this->processTypeSql($tPre . $columnName, $type, $filterValue, $qb);
} else {
$columnName = $filterKey;
if (is_array($filterValue)) {
$where[] = $this->processTypeSql($tPre . $columnName, 'in', $filterValue, $qb);
} else {
$where[] = $this->processTypeSql($tPre . $columnName, 'nequal', $filterValue, $qb);
}
}
}
return call_user_func_array(array($qb->expr(), 'andX'), $where);
}
示例2: index
public function index()
{
if (!Auth::check()) {
return LoginController::getIndex();
}
LoginController::updateUserPermissions();
//why not
# Trail
Trail::clear();
$tables = array_where(config('center.tables'), function ($key, $value) {
return !$value->hidden && LoginController::checkPermission($value->name, 'view');
});
$groups = $objects = [];
foreach ($tables as $table) {
$latest = DB::table($table->name)->leftJoin(config('center.db.users') . ' as u2', $table->name . '.updated_by', '=', 'u2.id')->select('u2.name as updated_name', $table->name . '.updated_at')->orderBy($table->name . '.updated_at', 'desc')->first();
if (!isset($groups[$table->list_grouping])) {
$groups[$table->list_grouping] = [];
}
$groups[$table->list_grouping][] = (object) ['title' => $table->title, 'list_grouping' => $table->list_grouping, 'link' => action('\\LeftRight\\Center\\Controllers\\RowController@index', $table->name), 'updated_name' => isset($latest->updated_name) ? $latest->updated_name : '', 'updated_at' => isset($latest->updated_at) ? $latest->updated_at : '', 'count' => number_format(DB::table($table->name)->count())];
}
foreach ($groups as $group) {
$objects = array_merge($objects, $group);
}
$table = new Table();
$table->rows($objects);
$table->column('title', 'string', trans('center::site.table'));
$table->column('count', 'integer', trans('center::site.count'));
$table->column('updated_name', 'updated_name', trans('center::site.updated_name'));
$table->column('updated_at', 'updated_at', trans('center::site.updated_at'));
$table->groupBy('list_grouping');
$table = $table->draw('tables');
return view('center::tables.index', compact('table'));
}
示例3: get
/**
* Return a single country by code
*
* @param sting $code
* @return array
*/
public static function get($code)
{
$result = array_where(static::$countries, function ($key, $value) use($code) {
return $value === $code;
});
return $result;
}
示例4: hasChangesExcept
public function hasChangesExcept(array $except)
{
$differences = array_where($this->getDifferences(), function ($key) use($except) {
return !in_array($key, $except);
});
return count($differences) > 0 ? true : false;
}
示例5: get
/**
* Return a single prefix by id
*
* @param integer $id
* @return array
*/
public static function get($id)
{
$result = array_where(static::$prefixes, function ($key, $value) use($id) {
return $value == $id;
});
return $result;
}
示例6: protectMethods
/**
* Protect Crud functions of controller.
*
* @return string
*/
protected function protectMethods()
{
$request = $this->request;
// available methods for resources.
$resources = $this->crud['resources'];
// protection methods being passed in a route.
$methods = $this->getAction('protect_methods');
// get method being called on controller.
$caller = $this->parseMethod();
// determine if we use resource or restful http method to protect crud.
$called = in_array($caller, $resources) ? $caller : $request->method();
// if controller is a resource or closure
// and does not have methods like
// UserController@index but only
// UserController we use crud restful.
$methods = is_array($methods) ? $methods : (in_array($caller, $resources) ? $this->crud['resource'] : $this->crud['restful']);
// determine crud method we're trying to protect
$crud = array_where($methods, function ($k, $v) use($called) {
return in_array($called, $v);
});
// crud method is read, view, delete etc
// match it against our permissions
// view.user or delete.user
// multiple keys like create,store?
// use OR operator and join keys with alias.
$permission = implode('|', array_map(function ($e) {
return $e . '.' . $this->parseAlias();
}, array_keys($crud)));
return !$this->forbiddenRoute() && $request->user()->can($permission);
}
示例7: flashInput
/**
* Flash only fields where flash = true
*
* @param array $fields
*/
protected function flashInput(array $fields)
{
$flash = array_where($fields, function ($key, $config) {
return $config['flash'];
});
Input::flashOnly(array_keys($flash));
}
示例8: index
public function index()
{
$forums = Forum::where("parent_id", 0)->with("subForums")->orderBy("left_id")->get();
$forums = array_where($forums, function ($_i, $forum) {
return $forum->canBeViewedBy(Auth::user());
});
return view("forum.forums.index", compact("forums"));
}
示例9: cityName
/**
* Get city name by pinyin.
*
* @param $pinyin
* @return mixed
*
* @author Cali
*/
public static function cityName($pinyin)
{
$cities = json_decode(File::get(database_path(self::CITIES_FILE_PATH)));
$city = array_where($cities, function ($key, $value) use($pinyin) {
return strtolower($value->pinyin) === strtolower($pinyin);
});
return is_null($city) || count($city) === 0 ? $pinyin : array_values($city)[0]->name;
}
示例10: getLanguage
public function getLanguage($languageCode)
{
$languages = $this->languages;
$language = array_where($languages, function ($key, $value) use($languageCode) {
return $value['code'] == $languageCode;
});
return current($language);
}
示例11: getThumbnails
public function getThumbnails(string $url)
{
$data = $this->getData($url);
$data = array_where($data['links']['thumbnail'], function ($key, $value) {
return $this->isImage($value);
});
$data = array_pluck($data, 'href');
return $data;
}
示例12: showSaved
public function showSaved()
{
$message = 'Looks like you have no template to show. Let\'s create one from <a class="btn btn-primary btn-flat" href="' . route("user::templates") . '">Template Gallery</a>';
$templates = Auth::user()->templates;
$savedTemplates = array_where($templates, function ($key, $template) {
return $template->htmlviewmenus->count() > 0;
});
$templatesCount = collect($savedTemplates)->count();
return view('my_template_view', compact('savedTemplates', 'templatesCount', 'message'))->with('user', Auth::user());
}
示例13: checkArray
private function checkArray($array)
{
$arr = array_where($array, function ($key, $value) {
if (is_array($value)) {
return $this->checkArray($value);
}
return !empty($value);
});
return $arr;
}
示例14: existDataArray
function existDataArray($data, $index)
{
if (isset($data[$index])) {
$array = array_where($data[$index], function ($key, $value) {
if (trim($value) != "") {
return $value;
}
});
} else {
$array = [];
}
return $array;
}
示例15: recordPrimaryImage
protected function recordPrimaryImage(array $images)
{
$primary_image = current(array_values(array_where($images, function ($key, $image) {
if ($image['category'] == 'primary') {
return true;
}
return false;
})));
if (empty($primary_image)) {
return;
}
$this->images_remembered[] = $this->getRememberableImage($primary_image);
$this->filtered_images[] = $primary_image;
}