0

在 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]->name,但不确定如何在不使用一系列 if/else 语句迭代 foreach 循环的情况下直接执行此操作。

4

1 回答 1

0

很简单:

$array_name[44]['name']

或者

$array_name[44]->name 
于 2013-04-01T00:22:59.147 回答