显示php数组的单个值

时间:2012-08-13 15:08:19

标签: php joomla

我有可以通过代码显示的数组:

foreach($form->data as $key => $value){
echo 'Key is '.$key.' and Value is '.$value.'<br />';
}

我得到以下显示:

Key is language and Value is lv-LV
Key is Itemid and Value is 114
Key is option and Value is com_content
Key is pumpis_1 and Value is 1
Key is lietussargs and Value is 2

但我只需显示[Itemid]的值,在这种情况下为114 我该怎么做? 谢谢! Raivis

2 个答案:

答案 0 :(得分:5)

echo $form->data['Itemid'];

或者如果你的意思是在foreach循环中(因为你还有其他东西要做),那么使用它:

foreach($form->data as $key => $value) {
    if( $key === 'Itemid' )
        echo $form->data['Itemid'];
}

答案 1 :(得分:1)

您应该阅读PHP arrays。语法是这样的:

echo $form->data['Itemid']