0
Array
(
    [1] => Array
        (
            [0] => Array
                (

                    [title] => New Car 
                    [description] => hi i am 
                )

            [1] => Array
                (

                    [title] => Honda city for sale!
                    [description] => I want to sell my Honda city ( Make-1998) ( Model- 1.5 Exi). The car has run for 
around 90000 kms. It is silver in colour.
                )

            [2] => Array
                (

                    [title] => Maruti Alto
                    [description] => Maruti AltoMaruti AltoMaruti AltoMaruti AltoMaruti AltoMaruti Alto
                )

        )

    [6] => Array
        (
            [0] => Array
                (

                    [title] => LG 1.5 AC
                    [description] => LG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 AC
                )

        )

)

我需要像这样在二维数组中收集所有值:

Array
(

          [0] => Array
                (

                    [title] => New Car 
                    [description] => hi i am 
                )

            [1] => Array
                (

                    [title] => Honda city for sale!
                    [description] => I want to sell my Honda city ( Make-1998) ( Model- 1.5 Exi). The car has run for 
around 90000 kms. It is silver in colour.
                )

            [2] => Array
                (

                    [title] => Maruti Alto
                    [description] => Maruti AltoMaruti AltoMaruti AltoMaruti AltoMaruti AltoMaruti Alto
                )


            [3] => Array
                (

                    [title] => LG 1.5 AC
                    [description] => LG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 AC
                )

        )

)

谢谢..

4

1 回答 1

2

这确实看起来非常像家庭作业......如果你确定只有两个级别,那么使用两个嵌套的 foreach 像这样:

$result = array();
foreach ($source as $subarray) {
foreach ($subarray as $item)
$result[] = $item;
}

如果您有更多级别,则需要一个递归函数。

于 2012-04-27T12:39:31.553 回答