2013-10-04 56 views
0

我是新來顯示他們的PHP ...我有兩個動態arrays..their列不同合併兩個不同的數組,然後使用的foreach

第一個數組:

Array 
(
    [0] => Array 
     (
      [id] => 102 
      [parent_id] => 94 
      [dir_name] => games 
      [size] => 
      [owner_id] => 10 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home/games 
      [shared] => 0 
      [comment] => 
      [add_date] => 07/30/2013 02:43 AM 
      [update_date] => 07/30/2013 02:43 AM 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/games 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 0 
      [allow_uploading] => 0 
      [share_date] => 
     ) 

    [1] => Array 
     (
      [id] => 122 
      [parent_id] => 94 
      [dir_name] => New Folder 
      [size] => 777835 
      [owner_id] => 10 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home/New Folder 
      [shared] => 0 
      [comment] => 
      [add_date] => 08/16/2013 08:31 AM 
      [update_date] => 08/16/2013 08:31 AM 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/New Folder 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 0 
      [allow_uploading] => 0 
      [share_date] => 
     ) 

    [2] => Array 
     (
      [id] => 98 
      [parent_id] => 94 
      [dir_name] => Videos 
      [size] => 
      [owner_id] => 10 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home/Videos/ 
      [shared] => 0 
      [comment] => 
      [add_date] => 07/30/2013 02:38 AM 
      [update_date] => 07/30/2013 02:38 AM 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/Videos/ 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 0 
      [allow_uploading] => 0 
      [share_date] => 
     ) 

    [3] => Array 
     (
      [id] => 97 
      [parent_id] => 94 
      [dir_name] => Pictures 
      [size] => 
      [owner_id] => 10 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home/Pictures/ 
      [shared] => 0 
      [comment] => 
      [add_date] => 07/30/2013 02:38 AM 
      [update_date] => 07/30/2013 02:38 AM 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/Pictures/ 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 0 
      [allow_uploading] => 0 
      [share_date] => 
     ) 

    [4] => Array 
     (
      [id] => 95 
      [parent_id] => 94 
      [dir_name] => Documents 
      [size] => 
      [owner_id] => 10 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home/Documents/ 
      [shared] => 1 
      [comment] => 
      [add_date] => 07/30/2013 02:38 AM 
      [update_date] => 07/30/2013 02:38 AM 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/Documents/ 
      [trash_status] => 1 
      [password] => 123456 
      [expires_after] => 5 
      [allow_uploading] => 0 
      [share_date] => 13-09-2013 
     ) 

    [5] => Array 
     (
      [id] => 96 
      [parent_id] => 94 
      [dir_name] => Music 
      [size] => 
      [owner_id] => 10 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home/Music/ 
      [shared] => 0 
      [comment] => dfdf 
      [add_date] => 07/30/2013 02:38 AM 
      [update_date] => 07/30/2013 02:38 AM 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/Music/ 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 0 
      [allow_uploading] => 0 
      [share_date] => 
     ) 

    [6] => Array 
     (
      [id] => 233 
      [parent_id] => 94 
      [dir_name] => test 
      [size] => 3945040 
      [owner_id] => 10 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home/test 
      [shared] => 0 
      [comment] => 
      [add_date] => 09/06/2013 09:16 AM 
      [update_date] => 09/06/2013 09:16 AM 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/test 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 0 
      [allow_uploading] => 0 
      [share_date] => 
     ) 

) 

第二陣列:

Array 
(
    [0] => Array 
     (
      [id] => 118 
      [name] => Desert.jpg 
      [size] => 845941 
      [type] => image/jpeg 
      [ext] => jpg 
      [shared] => 1 
      [shared_link] => http://creativevisionintl.com/dev/fwingo/usersdata/saqlain/Home//Desert.jpg 
      [comment] => 
      [owner_id] => 10 
      [dir_id] => 94 
      [path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/Home/Desert.jpg 
      [del_path] => /home1/creatkj8/public_html/dev/fwingo/usersdata/saqlain/HomeDesert.jpg 
      [dated] => 09/05/2013 07:15 AM 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 2 
      [share_date] => 06-09-2013 
     ) 

    [1] => Array 
     (
      [id] => 120 
      [name] => test.zip 
      [size] => 4096 
      [type] => Zip Archeive 
      [ext] => zip 
      [shared] => 0 
      [shared_link] => /Documentstest.zip 
      [comment] => 
      [owner_id] => 10 
      [dir_id] => 94 
      [path] => /Documentstest.zip 
      [del_path] => /Documentstest.zip 
      [dated] => 09/06/2013 09:21 AM 
      [trash_status] => 1 
      [password] => 
      [expires_after] => 0 
      [share_date] => 
     ) 

) 

注意:我想合併兩個數組,然後使用foreach循環顯示它們,兩個數組都有不同的列。
謝謝。 PLZ緊急重播。

+0

可能重複:http://stackoverflow.com/questions/8561987/php-merge-two-arrays – fluminis

+0

在@fluminis我情況這是不同的,我想合併它們,之後,顯示他們在一個表中使用每個或任何循環兩個數組有不同的索引。 :) – Zeeshan

+0

請不要在這裏說「緊急」。請參閱http://meta.stackexchange.com/a/6513以獲得一個很好的解釋。 – SirDarius

回答

0

例如合併兩個陣列

$a = array("red","green","yellow"); 
$b = array("a","b","c"); 
$c = array_merge($a,$b); 

print_r($c); 

foreach ($c as $key => $value) { 
    echo $value."<br>"; 
} 
0

首先,向陣列合併成一個:

//Merge the arrays 
$arrayEnd = array(); // define an array that will contain all the rows 

    //iterate on the first array assuming its name is $array1 
foreach($array1 as $val) { 
      //add the current line named $val to the resulting array 
    $arrayEnd[] = $val; 
} 
    //iterate on the first array assuming its name is $array1 
foreach($array1 as $val) { 
      //add the current line named $val to the resulting array 
    $arrayEnd[] = $val; 
} 

然後你只需要通過將得到的數組進行迭代:

//Display the resulting array 
foreach($arrayEnd as $val) { 
    echo $val['id']." - ".$val['name']; 
} 
+0

plz解釋更多我在這裏新.. .. :) – Zeeshan

0

比方說$a是你的第一個數組,$b是你的第二個數組,然後是merg給他們你可以通過下面的代碼來做到這一點。

$master = array_merge($a,$b); 

然後使用foreach循環用於獲取其內容像下面

foreach($master as $item){ 
    echo $item; 
} 
相關問題