[英]Returning php content array to string conversion error
I hava a php page where i have a function which does not print or echo to the page it returns a variable called content which is rendered on an html page. 我有一个php页面,其中有一个不打印或回显该页面的函数,它返回一个称为content的变量,该变量在html页面上呈现。 Throughout out this function i am appending to the content variable.
在整个函数中,我将附加到content变量。
i have an array ($myArray) which looks like 我有一个看起来像的数组($ myArray)
Array ( [0] => Array ( [0] => 2011-11-12 [1] => 1963-02-29 [3] => 2029-05-14 [9] => 1812-08-12 [11] => 1537-05-17 [16] => 2005-17-04 [30] => 3000-42-99 ) )
I am trying to loop through each item in $myArray and have it returned to the screen as a h1. 我试图遍历$ myArray中的每个项目,并将其作为h1返回到屏幕。
foreach($myArray as $item ){
$content .= '<h1>'.$item.'</h1>';
}
This results in me getting an 这导致我得到
Notice: Array to string conversion
error. 错误。
You have nested array , so do like below 您已嵌套数组,因此请执行以下操作
$arr=array ('0' => array ('0' => '2011-11-12' ,'1' => '1963-02-29' ,'3' => '2029-05-14' ,'9' => '1812-08-12' ,'11' => '1537-05-17' ,'16' => '2005-17-04' ,'30' => '3000-42-99')) ;
foreach($arr as $myArray){
foreach($myArray as $item ){
$content .= '<h1>'.$item.'</h1>';
}
}
echo $content;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.