2011-12-06 16 views
1

にあるかどうかを確認:SMARTY:値IがSmartyの、この多次元な配列有しmultimensionnalアレイ

attribute => Array (16) 
    25 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Blue" 
     id_product_attribute => "25" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "25" 
    26 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Blue" 
     id_product_attribute => "26" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "26" 
    27 => Array (2) 
    0 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "27" 
    1 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Yellow" 
     id_product_attribute => "27" 
    28 => Array (2) 
    0 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "28" 
    1 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Yellow" 
     id_product_attribute => "28" 
    29 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Metal" 
     id_product_attribute => "29" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "29" 
    30 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Metal" 
     id_product_attribute => "30" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "30" 
    32 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Black" 
     id_product_attribute => "32" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "32" 
    33 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Orange" 
     id_product_attribute => "33" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "33" 
    34 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Orange" 
     id_product_attribute => "34" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "34" 
    35 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Pink" 
     id_product_attribute => "35" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "35" 
    36 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Pink" 
     id_product_attribute => "36" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "36" 
    39 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Green" 
     id_product_attribute => "39" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "39" 
    40 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Green" 
     id_product_attribute => "40" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "40" 
    41 => Array (2) 
    0 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "41" 
    1 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Purple" 
     id_product_attribute => "41" 
    42 => Array (2) 
    0 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "8Go" 
     id_product_attribute => "42" 
    1 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Purple" 
     id_product_attribute => "42" 
    31 => Array (2) 
    0 => Array (3) 
     public_group_name => "Color" 
     attribute_name => "Black" 
     id_product_attribute => "31" 
    1 => Array (3) 
     public_group_name => "Disk space" 
     attribute_name => "16Go" 
     id_product_attribute => "31" 

を私はこの溶液linkにすべての配列のおかげを表示することができる:

{foreach from=$product.attribute key='id_attribute' item='attribute'} 

<li> 

    {foreach from=$attribute key='id_property' item='property'} 
     {$property.public_group_name} 
     {$property.attribute_name} 
    {/foreach} 

</li> 

{/ foreachの}

結果は次のようである:

  • カラーブルーディスクスペース16Go
  • カラーブルーディスクスペース8Go
  • ディスクスペース16Goカラーイエロー
  • ディスクスペース8Goカラーイエロー
  • 色メタルディスクスペース16Go
  • 色メタルディスクスペース8Go
  • カラーブラックディスクスペース8Go
  • カラーオレンジ色のディスクスペース16Go
  • カラーオレンジ色のディスクスペース8Go
  • カラーピンクのディスクスペース16Go
  • カラーピンクディスクスペース8Go
  • 色グリーンディスクスペース16Go
  • 色グリーンディスクスペース8Go
  • ディスクスペース16Goカラーパープル
  • ディスクスペース8Goカラーパープル
  • 色黒ディスクスペース16Go

ここでは、 "Blue"が含まれている行のみが表示されます。私はそれをどのように行うことができます

33 => Array (2) 
     0 => Array (3) 
      public_group_name => "Color" 
      attribute_name => "Orange" 
      id_product_attribute => "33" 
     1 => Array (3) 
      public_group_name => "Disk space" 
      attribute_name => "16Go" 
      id_product_attribute => "33" 

:彼は名前=オレンジ属性ましたので この配列には、表示されていないのだろうか? in_arrayを使用すると、値が多次元配列にあるかどうかを確認できますか?

答えて

1

Thxを私はこれが仕事をするかもしれないと思う:

{foreach from=$product.attribute key='id_attribute' item='attribute'} 
{* 
    Test if the first or second element of this array has 
    public_group_name "Color" 
    attribute_name "Blue" 
*} 
{if ($attribute[0].public_group_name == "Color" && $attribute[0].attribute_name == "Blue") || ($attribute[1].public_group_name == "Color" && $attribute[1].attribute_name == "Blue")} 
<li> 

    {foreach from=$attribute key='id_property' item='property'} 
     {$property.public_group_name} 
     {$property.attribute_name} 
    {/foreach} 

</li> 
{/if} 
{/foreach} 
+0

PBは、色の属性が最初に常にではないということである:配列[0]。おそらく: {if $ attribute [0] .public_group_name == "Blue"や$ attribute [1] etc ...} – prestarocket

+0

@adokaraはい、そうです。上記で編集します。 –