2012-05-04 65 views
0

我有一個像這樣的數組:$array1
我正在使用循環來顯示數組的值。我想顯示所有數組值。
,但需要顯示這樣的 -想要以特定的方式顯示數組

Slovenly Europe 
      1. [0] => /7/0/702-100_thumb-sm_1.jpg 
      [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     2. [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 


Greece 
      1. [0] => /7/0/702-100_thumb-sm_1.jpg 
      [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     2. [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 
     3. [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 



foreach($array1 as $v){ 
    $v['storename']; } 


$array1 = Array 
(
    [0] => Array 
     (
      [0] => /7/0/702-100_thumb-sm_1.jpg 
      [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     [storename] => Slovenly Europe 
    ) 

[1] => Array 
    (
     [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     [storename] => Slovenly Europe 
    ) 

[2] => Array 
    (
     [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     [storename] => Slovenly Europe 
    ) 

[3] => Array 
    (
     [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     [storename] => Greece 
    ) 

[4] => Array 
    (
     [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     [storename] => Greece 
    ) 

[5] => Array 
    (
     [0] => /7/0/702-100_thumb-sm_1.jpg 
     [thumbnail] => /7/0/702-100_thumb-sm_1.jpg 

     [storename] => Greece 
    ) 

回答

0

你必須首先改造陣列:

$tree = array); 
foreach ($array1 as $store_info) { 
    $tree[$store_info['storename']][] = array(
     '0' => $store_info['0'], 
     'thumbnail' => $store_info['thumbnail'], 
    ); 
} 

print_r($tree); 

希望你可以從那裏找出休息。

0

請嘗試以下給出代碼..

/*Get unique value of storename from $array1*/ 
$store_arr = array(); 
foreach ($array1 AS $key => $value) { 

    if (!in_array($value['storename'], $store_arr)) { 
     $store_arr[] = $value['storename']; 
    } 
} 

foreach ($store_arr AS $store) { 
    echo $store."<br/>"; 
    $i = 1; 
    foreach ($array1 AS $arrs) { 
     if ($store == $arrs['storename']) { 
      echo "{$i}."; 
      echo "[0]=>{$arrs[0]}<br/>"; 
      echo "[thumbnail]=>{$arrs[thumbnail]}<br/>"; 
      $i++; 
     } 

    } 
} 

感謝