故障包括另一个数组的数组输出 [英] Trouble including array output in another array

查看:118
本文介绍了故障包括另一个数组的数组输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

  $标签= get_tags(阵列('排除'=> 46,5,101,22,122,7,102,15,104,47,105,66,43,123,'田'=> IDS)) ;
$ tagString =破灭('',$标记);
回声$ tagString;

这回声出来的...
10,121,20,36,23,66,24,21,105,76,82,17,22,122,43,47,102,5,6,106,8,75,54,38,57,86,56,101,123,95,25,62,16,39,40,69,37,9,42,7,15,41,87,73,85,104

这是伟大的。不过,其实我是想包含的结果(这是我的猜测是$ tagString)在另一个数组如下...

 的$ args =阵列(
    post_type'=> 后,
    posts_per_page'=> 12,
    '分页'=> $分页,
    tag__in'=>阵列(46,5,101,22,122,7,102,15,104,47,105,66,43,123)
    tag__not_in'=>阵列($ tagString)
);

我试过删除括号加单/双/无报价,去除所有组合$ tagString前面的单词数组,但它只是不工作。当我手动创建...

 'tag__not_in'=>阵列(10,121,20,36,23,24,21,76,82,17,6,106,8,75,54,38,57,86,56,95,25,62,16,39,40,69, 37,9,42,41,87,73,85)

在code完美的作品。我怎样才能从$ tagString输出是括号内tag__not_in数组的内容?这可能吗?

========

更新,以反映阿迈勒的code ...

  $标签= get_tags(阵列('排除'=> 46,5,101,22,122,7,102,15,104,47,105,66,43,123,'田'=> IDS)) ;
$ tagString =破灭('',$标记);
回声$ tagString;的$ args =阵列(
    post_type'=> 后,
    posts_per_page'=> 12,
    '分页'=> $分页,
    tag__in'=>阵列(46,5,101,22,122,7,102,15,104,47,105,66,43,123)
    / *'tag__not_in'=>排列(10,121,20,36,23,24,21,76,82,17,6,106,8,75,54,38,57,86,56,95,25,62,16,39,40,69,37,9,42,41,87,73,85)*/
    tag__not_in'=>爆炸(,,$ tagString)
);


解决方案

$ tagString 是一个字符串 - 只需在将其插入阵列(.. 。)不会创建一个数组(除非你使用的eval(),这通常是一个坏主意)。只需使用 爆炸() 创建从逗号数组 - 分隔字符串,像这样:

 'tag__not_in'=>爆炸(,,$ tagString)

I have the following code:

$tags = get_tags(array('exclude' => 46,5,101,22,122,7,102,15,104,47,105,66,43,123, 'fields' => ids));
$tagString = implode (',' , $tags);
echo $tagString;

Which echos out as... 10,121,20,36,23,66,24,21,105,76,82,17,22,122,43,47,102,5,6,106,8,75,54,38,57,86,56,101,123,95,25,62,16,39,40,69,37,9,42,7,15,41,87,73,85,104

This is great. However, I actually want to include the result (which I guess is $tagString) in another array as follows...

$args = array(
    'post_type' => 'post', 
    'posts_per_page' => 12,
    'paged' => $paged,
    'tag__in' => array (46, 5, 101, 22, 122, 7, 102, 15, 104, 47, 105, 66, 43, 123),
    'tag__not_in' => array ($tagString)
);

I've tried removing brackets adding single / double / no quotes, removing the word 'array' in front of $tagString across all combinations but it just doesn't work. When I manually create...

'tag__not_in' => array (10,121,20,36,23,24,21,76,82,17,6,106,8,75,54,38,57,86,56,95,25,62,16,39,40,69,37,9,42,41,87,73,85)

The code works perfectly. How can I get the output from $tagString to be the content of 'tag__not_in' array within the brackets? Is this possible?

========

Update to reflect Amal's code...

$tags = get_tags(array('exclude' => 46,5,101,22,122,7,102,15,104,47,105,66,43,123, 'fields' => ids));
$tagString = implode (',' , $tags);
echo $tagString;

$args = array(
    'post_type' => 'post', 
    'posts_per_page' => 12,
    'paged' => $paged,
    'tag__in' => array (46, 5, 101, 22, 122, 7, 102, 15, 104, 47, 105, 66, 43, 123),
    /*'tag__not_in' => array (10,121,20,36,23,24,21,76,82,17,6,106,8,75,54,38,57,86,56,95,25,62,16,39,40,69,37,9,42,41,87,73,85)*/
    'tag__not_in' => explode(',', $tagString)
);

解决方案

$tagString is a string - simply inserting it in array(...) won't create an array (unless you use eval(), which is generally a bad idea). Simply use explode() to create an array from the comma-separated string, like so:

'tag__not_in' => explode(',', $tagString)

这篇关于故障包括另一个数组的数组输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆