My var_dump looks like this, I know that I'm getting the error because I'm passing an array instead of a string. But how can I solve it?
array
0 =>
array
'date_submitted' => string '2012-03-22 19:28:22' (length=19)
1 =>
array
'date_submitted' => string '2012-03-28 21:31:28' (length=19)
My function
function getArticle() {
$article = new Article('x');
$arr = $article->getArticles();
$date= null;
foreach($arr as $record){
$currentDate = date('l, F j', strtotime($record['date_submitted']));
if ($currentDate != $date) {
echo set_format_date($record['date_submitted'],'l, F j');
}
$date = $currentDate;
}
}
Tried using $x=0;
then $x++;
but that returns Undefined offset: 0
like this $record[$x]['date_submitted'];
, it didnt work.
var_dump($record);
within the loop to see why it's telling you that - Crashspeeder 2012-04-03 20:49
strtotime
call. Please show us the code for set_format_date
as well - since this function isn't bundled with vanilla php - Khôi 2012-04-03 20:51
if you wish to manipulate the array itself inside a foreach loop, you have to reference the value.
foreach($arr as &$record){
// ...
}
if you manipulate $record now inside the loop, $arr will actually contain the values you manipulated. otherwise $record is just in scope of the loop.