获得数组3级的值

时间:2012-06-01 20:38:06

标签: php arrays

如何从以下数组中检索[terms]的值来构成字符串(20,21,22 ...,n)?非常感谢您的帮助。

    Array
(
    [post_type] => Array
        (
            [0] => hotel
        )

    [posts_per_page] => 15
    [tax_query] => Array
        (
            [0] => Array
                (
                    [taxonomy] => facility
                    [field] => id
                    [terms] => 20
                )

            [1] => Array
                (
                    [taxonomy] => facility
                    [field] => id
                    [terms] => 21
                )

            [2] => Array
                (
                    [taxonomy] => facility
                    [field] => id
                    [terms] => 22
                )
            .
            .
            .
            [*n*] => Array
                (
                    [taxonomy] => facility
                    [field] => id
                    [terms] => *n*
                )


            [relation] => AND
        )

    [orderby] => title
    [order] => ASC
    [post_status] => publish
    [paged] => 1
)

1 个答案:

答案 0 :(得分:1)

试试这个:

$terms = array();
foreach( $array['tax_query'] as $item)
    $terms[] = $item['terms'];

echo '(' . implode( ',', $terms) . ')';