我有一个多维阵列,其中每个条目看起来如下获取键和值:从在foreach循环一个多维阵列(PHP/HTML)
$propertiesMultiArray['propertyName'] = array(
'formattedName' => 'formattedNameValue',
'example' => 'exampleValue',
'data' => 'dataValue');
我具有其中我想使用一种形式一个用于填充值和输入字段特征的foreach循环,使用外部数组中的键以及存储在内部数组中的不同信息。所有值将被用作字符串。到目前为止,我有
foreach($propertiesMultiArray as $key => $propertyArray){
echo "<p>$propertyArray['formattedName'] : " .
"<input type=\"text\" name=\"$key\" size=\"35\" value=\"$propertyArray['data']\">" .
"<p class=\"example\"> e.g. $propertyArray['example'] </p>" .
"<br><br></p>";
}
我想HTML段类似于以下内容:
formattedNameValue : dataValue
e.g. exampleValue
其中dataValue是在输入文本字段和$键用作名字提交输入到表格。基本上我想要$ key =“propertyName”。然而,它提供了以下错误:
syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
如何从多维一个的内部数组访问信息,但获取在同一时间的关键?
我在下面回答了我自己,但是你的printf选项是我学到的新东西,它看起来很棒,我现在要切换到它,它会使事情变得非常干净,谢谢 –
谢谢!为了告诉我关于我的HTML错误 – Jhay
不客气。 –