Php 如何在多维数组中打印特定值
我尝试了很多方法来打印出一个特定的值,例如使用array_column,但没有任何效果 我的阵列Php 如何在多维数组中打印特定值,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我尝试了很多方法来打印出一个特定的值,例如使用array_column,但没有任何效果 我的阵列 $items = [array('content' => 'test1','price' => 500,'itemno' => '1'),array('content' => 'test2','price' => 300,'itemno' => '2'),array('content' => 'test3','price' => 100,'itemno
$items = [array('content' => 'test1','price' => 500,'itemno' => '1'),array('content' => 'test2','price' => 300,'itemno' => '2'),array('content' => 'test3','price' => 100,'itemno' => '3')];
或
php代码
foreach ($items as $key => $item) {
foreach ($item as $item1) {
echo $item1['content'] ;
}}
每次我尝试使用某个值的键打印该值时,都会出现这些错误
警告:中的字符串偏移量“content”非法
第28行C:\xampp\htdocs\test\classes\index.php警告:非法
上的C:\xampp\htdocs\test\classes\index.php中的字符串偏移量“content”
第28行1警告:中的非法字符串偏移量“content”
第28行的C:\xampp\htdocs\test\classes\index.php警告:非法
上的C:\xampp\htdocs\test\classes\index.php中的字符串偏移量“content”
第28行2警告:中的非法字符串偏移量“content”
第28行C:\xampp\htdocs\test\classes\index.php警告:非法
上的C:\xampp\htdocs\test\classes\index.php中的字符串偏移量“content”
第28行3
您根本不需要第二个循环:
foreach($items作为$item){echo$item['content'];}
。我觉得自己很愚蠢。无论如何,当有两个数组时,它是如何使用一个循环的?$item
是下一个具有内容
键的数组$item['content']
在content
键下获取下一个数组的值。谢谢,但是当有两个数组时,它是如何使用一个循环的呢这是一个多维数组,您还有其他示例吗?
foreach ($items as $key => $item) {
foreach ($item as $item1) {
echo $item1['content'] ;
}}
foreach($items as $key => $item) {
echo $items[$key]['content'];
}