php 合并数组合并
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 合并数组合并相关的知识,希望对你有一定的参考价值。
<?php
if(!empty($_GET['bedrooms']))
{
$args_filters['tax_query'][] = array('taxonomy' => 'bedrooms', 'terms' => $_GET['bedrooms']);
}
if(!empty($_GET['neighborhood']))
{
$args_filters['tax_query'][] = array('taxonomy' => 'neighborhood', 'terms' => $_GET['neighborhood']);
}
$args_main = array('post_type' => 'apartments', 'post_status' => 'publish', 'showposts' => -1);
if($args_filters){
$args_final = array_merge($args_main, $args_filters);
}else{
$args_final = $args_main;
}
query_posts($args_final);
?>
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args_filters = array();
if(!empty($_GET['keywords'])){
$args_filters['s'] = $_GET['keywords'];
}
if(!empty($_GET['yearly-salary'])){
$args_filters['tax_query']['0'] = array('taxonomy' => Salary_Tax, 'field' => 'slug', 'terms' => $_GET['yearly-salary']);
}
if(!empty($_GET['hourly-salary'])){
$args_filters['tax_query']['0'] = array('taxonomy' => Salary_Tax, 'field' => 'slug', 'terms' => $_GET['hourly-salary']);
}
if(!empty($_GET['category'])){
$args_filters['tax_query']['1'] = array('taxonomy' => Category_Tax, 'field' => 'slug', 'terms' => $_GET['category']);
}
if(!empty($_GET['specialty'])){
$args_filters['tax_query']['2'] = array('taxonomy' => Specialties_Tax, 'field' => 'slug', 'terms' => $_GET['specialty']);
}
if(!empty($_GET['location'])){
$args_filters['tax_query']['3'] = array('taxonomy' => Location_Tax, 'field' => 'slug', 'terms' => $_GET['location']);
}
if(!empty($_GET['jobtype'])){
$args_filters['tax_query']['4'] = array('taxonomy' => Jobtype_Tax, 'field' => 'slug', 'terms' => $_GET['jobtype']);
}
$args_main = array('post_type' => 'post', 'post_status' => 'publish', 'paged' => $paged);
$args_final = array_merge($args_main, $args_filters);
print_r($args_final);
query_posts($args_final);
?>
<?php
$args_sale = array();
if(isset($_POST['for-sale']) && !empty($_POST['for-sale']) && empty($_POST['for-lease']))
{
$args_sale['tax_query']['0'] = array('taxonomy' => PropertySale,'field' => 'slug','terms' => array(ForSaleTaxonomy));
}
if(isset($_POST['for-lease']) && !empty($_POST['for-lease']) && empty($_POST['for-sale']))
{
$args_sale['tax_query']['0'] = array('taxonomy' => PropertySale,'field' => 'slug','terms' => array(ForLeaseTaxonomy));
}
if(isset($_POST['for-sale']) && !empty($_POST['for-sale']) && isset($_POST['for-lease']) && !empty($_POST['for-lease']))
{
$args_sale['tax_query']['0'] = array('taxonomy' => PropertySale,'field' => 'slug','terms' => array( ForSaleTaxonomy, ForLeaseTaxonomy));
}
if(isset($_POST['address']) && !empty($_POST['address']))
{
$args_sale['meta_query']['0'] = array('mkey' => 'address', 'value' => $_POST['address'], 'compare' => 'LIKE');
}
if(isset($_POST['propertytype']) && !empty($_POST['propertytype']))
{
$args_sale['tax_query']['1'] = array('taxonomy' => PropertyType ,'field' => 'slug','terms' => $_POST['propertytype']);
}
if(isset($_POST['pricefrom']) && !empty($_POST['pricefrom']) && $_POST['pricefrom'] != '0.00' && $_POST['priceto'] == '0.00')
{
$args_sale['meta_query']['1'] = array('key' => 'price', 'value' => $_POST['pricefrom'], 'type' => 'numeric', 'compare' => '>=');
}
if(isset($_POST['priceto']) && !empty($_POST['priceto']) && $_POST['priceto'] != '0.00' && $_POST['pricefrom'] == '0.00')
{
$args_sale['meta_query']['1'] = array('key' => 'price', 'value' => $_POST['priceto'], 'type' => 'numeric', 'compare' => '<=');
}
if(isset($_POST['pricefrom']) && !empty($_POST['pricefrom']) && $_POST['pricefrom'] != '0.00' && !empty($_POST['priceto']) && !empty($_POST['priceto']) && $_POST['priceto'] != '0.00')
{
$args_sale['meta_query']['1'] = array('key' => 'price', 'value' => array($_POST['pricefrom'],$_POST['priceto']), 'type' => 'numeric', 'compare' => 'BETWEEN');
}
if(isset($_POST['squarefeetfrom']) && !empty($_POST['squarefeetfrom']) && $_POST['squarefeetfrom'] != '0.00' && $_POST['squarefeetto'] == '0.00')
{
$args_sale['meta_query']['2'] = array('key' => 'square-feet', 'value' => $_POST['squarefeetfrom'], 'type' => 'numeric', 'compare' => '>=');
}
if(isset($_POST['squarefeetto']) && !empty($_POST['squarefeetto']) && $_POST['squarefeetto'] != '0.00' && $_POST['squarefeetfrom'] == '0.00')
{
$args_sale['meta_query']['2'] = array('key' => 'square-feet', 'value' => $_POST['squarefeetto'], 'type' => 'numeric', 'compare' => '<=');
}
if(isset($_POST['squarefeetfrom']) && !empty($_POST['squarefeetfrom']) && $_POST['squarefeetfrom'] != '0.00' && !empty($_POST['squarefeetto']) && !empty($_POST['squarefeetto']) && $_POST['squarefeetto'] != '0.00')
{
$args_sale['meta_query']['2'] = array('key' => 'square-feet', 'value' => array($_POST['squarefeetfrom'],$_POST['squarefeetto']), 'type' => 'numeric', 'compare' => 'BETWEEN');
}
if(isset($_POST['roomfrom']) && !empty($_POST['roomfrom']) && empty($_POST['roomto']))
{
$args_sale['meta_query']['3'] = array('key' => 'rooms', 'value' => $_POST['roomfrom'], 'type' => 'numeric', 'compare' => '>=');
}
if(isset($_POST['roomto']) && !empty($_POST['roomto']) && empty($_POST['roomfrom']))
{
$args_sale['meta_query']['3'] = array('key' => 'rooms', 'value' => $_POST['roomto'], 'type' => 'numeric', 'compare' => '<=');
}
if(isset($_POST['roomfrom']) && !empty($_POST['roomfrom']) && !empty($_POST['roomto']) && !empty($_POST['roomto']))
{
$args_sale['meta_query']['3'] = array('key' => 'rooms', 'value' => array($_POST['roomfrom'],$_POST['roomto']), 'type' => 'numeric', 'compare' => 'BETWEEN');
}
if(isset($_POST['keyword']) && !empty($_POST['keyword']))
{
$args_sale['s'] = $_POST['keyword'];
}
$args_main = array('post_type' => 'property', 'post_status' => 'publish', 'paged' => $paged);
$args_final = array_merge($args_main, $args_sale);
print_r($args_final);
?>
以上是关于php 合并数组合并的主要内容,如果未能解决你的问题,请参考以下文章