开发者

send several return with array. how is it?

i want results this code send for AJAX CALL, this have 2 result. did must send with array? how is it?

now return is: '1'

$date_go = '1111/11/11';
$date_back = '1390/00/05';

$jdate = jgmdate("Y/m/j");
list($year_now, $month_now, $day_now) = explode('/', $jdate, 3);

list($year_back, $month_back, $day_back) = explode('/', $date_back, 3);
list($year_go, $month_go, $day_go) = explode('/', $date_go, 3);            
if($year_go>=$year_now && $month_go<=12 && $year_back>=$year_now && $month_back<=12) {

    $j2g开发者_Go百科_back = $this->convert_date->JalaliToGregorian($year_back, $month_back, $day_back);
    return array($j2g_back[0]."/".$j2g_back[1]."/".$j2g_back[2]);

    $j2g_go = $this->convert_date->JalaliToGregorian($year_go, $month_go, $day_go);
    return array($j2g_go[0]."/".$j2g_go[1]."/".$j2g_go[2]);


You are returning an array containing only 1 element, try it like this:

$my_array = array();
if($year_go>=$year_now && $month_go<=12 && $year_back>=$year_now && $month_back<=12) 
{
    $j2g_back = $this->convert_date->JalaliToGregorian($year_back, $month_back, $day_back);
    $my_array[] = $j2g_back[0]."/".$j2g_back[1]."/".$j2g_back[2];
    $j2g_go = $this->convert_date->JalaliToGregorian($year_go, $month_go, $day_go);
    $my_array[] = $j2g_go[0]."/".$j2g_go[1]."/".$j2g_go[2];
}
return json_encode($my_array);

This way you add 2 elements to the array, and returning the JSON-encoded array.


Return only works in a function. Is this code wrapped in a function?

If you wish to return both arrays you must add them to a single array and call json_encode

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜