php从数组中获取属性名的值
我的数据库中存储了一个数组。所以当我尝试:php从数组中获取属性名的值,php,arrays,Php,Arrays,我的数据库中存储了一个数组。所以当我尝试:print\r($arrayname) 结果是这样的: Array ( [0] => Color,Processor [attribute_name] => Color,Processor ) 我想获得[attribute\u name]=>颜色、处理器的值 到目前为止,我将foreach循环如下: foreach ($arraylist as $name) { echo $name['attribute_nam
print\r($arrayname)
结果是这样的:
Array
(
[0] => Color,Processor
[attribute_name] => Color,Processor
)
我想获得[attribute\u name]=>颜色、处理器的值
到目前为止,我将foreach
循环如下:
foreach ($arraylist as $name) {
echo $name['attribute_name];
}
但它像cc一样显示结果。有人能告诉我如何从数据库中获取值吗?请试试这个
foreach ($arraylist as $key => $name) {
if($key == 'attribute_name')
echo $name;
}
实际上你不需要使用foreach
你可以这样访问它
echo $arraylist["attribute_name"];
您是否输入了错别字,或者正在使用echo$name['attribute_name]运行代码;(缺少结束引号)?它正在重复值..如Color、ProcessorColor、ProcessorPls使用print\r($arraylist)检查数组;或者只需使用echo$arraylist[“attribute_name”];