我有一个像$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 :(得分:0)
您必须首先转换数组:
$tree = array);
foreach ($array1 as $store_info) {
$tree[$store_info['storename']][] = array(
'0' => $store_info['0'],
'thumbnail' => $store_info['thumbnail'],
);
}
print_r($tree);
希望你能从中找出其余部分。
答案 1 :(得分: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++;
}
}
}
感谢