2012-04-27 113 views
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 
       ) 

     ) 

) 

謝謝..

+0

請問您可以標記語言嗎? – ericosg 2012-04-27 12:00:34

+0

耶其PHP和我不能夠得到主陣列的最後(第六)值[6] =>數組 ( [0] =>數組 ( [標題] => LG 1.5 AC [描述] => LG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 ACLG 1.5 AC ) )我試過了($ j = 0; $ j mayank 2012-04-27 12:07:38

+2

聞起來像'家庭作業' – 2012-04-27 12:07:39

回答

2

這的確看起來非常像功課... 如果你肯定只有兩個級別,然後使用兩個嵌套的foreach像這樣:

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

如果你有更多的級別,你需要一個遞歸函數。