質問編集履歴
1
配列構造の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
smartyのforeachプロパティで、例えば要素を6番目まで
|
3
3
|
取り出すには以下のような書き方になると思います。
|
4
4
|
```PHP
|
5
|
-
{foreach
|
5
|
+
{foreach from=$array item="i" key="k" name="n"}
|
6
6
|
{if $smarty.foreach.n.index < 6}
|
7
7
|
<li><img src="{$i.image}" alt="sample"></li>//6番目までのアイテムとキーが出力
|
8
8
|
{/if}
|
@@ -14,11 +14,29 @@
|
|
14
14
|
ご指南いただけたら嬉しいです。
|
15
15
|
|
16
16
|
```PHP
|
17
|
-
{foreach
|
17
|
+
{foreach from=$array item="i" key="k" name="n"}
|
18
18
|
{if $smarty.foreach.n.index >= 7}
|
19
19
|
<li><img src="{$i.image}" alt="sample"></li>//7番目のアイテムとキーだけ表示される...
|
20
20
|
{/if}
|
21
21
|
{/foreach}
|
22
22
|
```
|
23
23
|
|
24
|
-
Smartyのversionは2.6.25です。
|
24
|
+
Smartyのversionは2.6.25です。
|
25
|
+
|
26
|
+
-------------------------------------------------------------------------------
|
27
|
+
|
28
|
+
foreachの配列構造は以下のような多次元配列の場合で仮定しています。
|
29
|
+
smarty debug consoleをイメージして頂けたらと思います。
|
30
|
+
```PHP
|
31
|
+
{$array} -> Array (8)
|
32
|
+
item1 => Array(2)
|
33
|
+
sample_id => "12345"
|
34
|
+
sample_id2 => "67890"
|
35
|
+
item2 => Array(2)
|
36
|
+
sample_id => "23456"
|
37
|
+
sample_id2 => "78901"
|
38
|
+
//~~省略~~
|
39
|
+
item8 => Array(2) //itemは8個まで
|
40
|
+
sample_id => "90123"
|
41
|
+
sample_id2 => "12345"
|
42
|
+
```
|