想要三个数组,没有foreach和index

时间:2017-11-07 06:24:01

标签: php arrays

我有一个数组和三个数组,我希望将这三个数组作为单独的数组,没有任何索引。 我必须将它放在元查询中,我需要它完全像那样。

foreach( $skill_obj_arr as $skills_query ){

    $meta_query[] = array(

           'key' => 'cs_skills', 
           'value' => sprintf(':"%s";', $skills_query),  
           'compare' => 'LIKE' );
        }   

    echo "<pre>";
    print_r($meta_query);
    echo "</pre>";


Array
(
[0] => Array
    (
        [key] => cs_skills
        [value] => :"content-writer";
        [compare] => LIKE
    )

[1] => Array
    (
        [key] => cs_skills
        [value] => :"data-scientist";
        [compare] => LIKE
    )

[2] => Array
    (
        [key] => cs_skills
        [value] => :"front-end-developer";
        [compare] => LIKE
    )
 )

这就是我希望它们在一个变量中的方式,它是如何可能的。 ▼▼▼

Array
    (
        [key] => cs_skills
        [value] => :"content-writer";
        [compare] => LIKE
    )

Array
    (
        [key] => cs_skills
        [value] => :"data-scientist";
        [compare] => LIKE
    )

Array
    (
        [key] => cs_skills
        [value] => :"front-end-developer";
        [compare] => LIKE
    )

1 个答案:

答案 0 :(得分:0)

我想你想要这样的东西: -

$args = array('meta_query' => array()); //this is args array

$meta_query = [];
foreach( $skill_obj_arr as $skills_query ){

    $meta_query[] = array(
           'key' => 'cs_skills', 
           'value' => sprintf(':"%s";', $skills_query),  
           'compare' => 'LIKE' 
       );
}
$args['meta_query'] = array('relation' => 'OR',$meta_query); //assign all meta-tags array to the argument array

print_r($args);

输出: - https://eval.in/894282

参考文献: - https://tommcfarlin.com/wp_query-and-multiple-meta-keys/

参考代码的输出: - https://eval.in/894281