如何在smarty w / o foreach中提取数组var值

时间:2013-03-31 15:46:59

标签: multidimensional-array smarty

在Smarty中打印出一个数组(复杂)时(从{$ myarray-> get_fields()| print_r打印),我得到以下列表:

Array
(
[44] => stdClass Object
    (
        [id] => 44
        [name] => Address 2
        [type] => textbox
        [max_length] => 255
        [create_date] => 2013-03-25 10:02:02
        [modified_date] => 2013-03-25 10:02:02
        [item_order] => 
        [admin_only] => 0
        [public] => 1
        [dropdown_data] => 
        [data] => 
        [fielddef_id] => 44
        [value] => Halifax
    )

[47] => stdClass Object
    (
        [id] => 47
        [name] => Address 3
        [type] => textbox
        [max_length] => 255
        [create_date] => 2013-03-25 10:02:56
        [modified_date] => 2013-03-25 10:02:56
        [item_order] => 
        [admin_only] => 0
        [public] => 1
        [dropdown_data] => 
        [data] => 
        [fielddef_id] => 47
    )

[50] => stdClass Object
    (
        [id] => 50
        [name] => Address 4
        [type] => textbox
        [max_length] => 255
        [create_date] => 2013-03-25 10:03:40
        [modified_date] => 2013-03-25 10:03:40
        [item_order] => 
        [admin_only] => 0
        [public] => 0
        [dropdown_data] => 
        [data] => 
        [fielddef_id] => 50
    )
)

我想打印出来直接打印数组(44)中set中第一个数组的[value]字段。基本上,我想打印[44] - >名称,但不知道如何直接执行此操作而不使用一系列if / else语句迭代foreach循环。

1 个答案:

答案 0 :(得分:0)

简单如下:

$array_name[44]['name']

$array_name[44]->name