При использовании объектов вы должны использовать вызовы объектов.пример
$object -> objectcontent
в вашем случае это будет
$arr_date[0]->date
Посмотрите на это
//Defining my object to look like yours. I just set the year to 2012 so the while will succeed.
$array = array("date" => "2012-10-20", "page_views" => 2);
$object = (object) $array;
$arr_date[] = $object;
//Making an increment variabel
$i = 0;
while (true) {
$page_ctr++;
//Setting my array $arr_date to iterate through the increment variabel, and output the objects content with the name date
if (date('Y-m', strtotime($arr_date[$i]->date)) > date('Y-m')) {
$total_pages = $page_ctr;
break;
}
//Increasing my increment variabel.
$i++;
}
//printing the total pages.
print $total_pages;
Тем не менее, на вашем месте я бы использовалЦикл foreach, который выполняет итерации по массиву
//Setting increment variable $page_ctr to zero
$page_ctr = 0;
//Starting foreach array and asking the arrays key value to be set in $key and the value to
//be set in $value. in this case $value will be the object
foreach ($arr_date as $key=>$value) {
//increasing the increment variable by one
$page_ctr++;
//checking your objects date against the current date to see if its bigger.
if (date('Y-m', strtotime($value->date)) > date('Y-m')) {
$total_pages = $page_ctr;
//Breaking
break;
}
}
Это готовый к копированию код для тестирования и проверки.
<?php
$array = array("date" => "2012-10-20", "page_views" => 2);
$object = (object) $array;
$arr_date[] = $object;
$page_ctr = 0;
$total_pages = 0;
foreach ($arr_date as $key=>$value) {
$page_ctr++;
if (date('Y-m', strtotime($value->date)) > date('Y-m')) {
$total_pages = $page_ctr;
break;
}
}
print $total_pages;
?>