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
    )
4

2 回答 2

0

您必须先转换数组:

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

print_r($tree);

希望你能从那里找出其余的。

于 2012-05-04T05:49:34.180 回答
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++;
        }

    }
}

谢谢

于 2012-05-04T05:49:47.503 回答