我想让阵列看起来像这样。 请查看并比较代码,以便您直接了解我的意思。
$args = array(
'numberposts' => -1,
'post_type' => 'post',
'cat' => array(
1, 2, 3
),
'meta_query' => array(
'relation' => 'OR',
/*
array(
'key' => 'year',
'value' => '2014',
'compare' => 'LIKE'
),
array(
'key' => 'year',
'value' => '2013',
'compare' => 'LIKE'
)
*/
$getarray
),
'suppress_filters' => false
);
但是当我这样做时,我仍然得到编号的输出:
array_push(
$getarray,
array(
'key' => 'organization_type',
'value' => $val,
'compare' => 'LIKE'
)
);
的var_dump:
array(1) { [0]=> array(3) { ["key"]=> string(17) "organization_type" ["value"]=> string(10) "foundation" ["compare"]=> string(4) "LIKE" } }
如何使数组包含如下数组:
array(
'key' => 'year',
'value' => '2014',
'compare' => 'LIKE'
),
array(
'key' => 'year',
'value' => '2013',
'compare' => 'LIKE'
)
答案 0 :(得分:0)
这是你在寻找什么?
$array = array();
$array['key'] = "year";
$array['value'] = "2014";
$array['compare'] = "LIKE";
foreach($array as $i){
echo "$i";
}
答案 1 :(得分:0)
经过一番猜测后,我想你要问的是:
array(
'key' => 'year',
'value' => '2014',
'compare' => 'LIKE'
),
array(
'key' => 'year',
'value' => '2013',
'compare' => 'LIKE'
)
使用关联索引(即单词而不是数字)进入另一个数组。它看起来像这样:
array(
'array1' => array(
'key' => 'year',
'value' => '2014',
'compare' => 'LIKE'
),
'array2' => array(
'key' => 'year',
'value' => '2013',
'compare' => 'LIKE'
)
);
换句话说,您必须指定要用作索引的单词。你也可以这样做:
$arr = array();
$arr['array1'] = array(
'key' => 'year',
'value' => '2014',
'compare' => 'LIKE'
);
$arr['array2'] = array(
'key' => 'year',
'value' => '2013',
'compare' => 'LIKE'
);