problem with array_push

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • grace01
    New Member
    • Sep 2007
    • 6

    problem with array_push

    Hello,

    My php program cannot display result correctly. After run array_push($y_o ptions,$tmp_yr) , $y_options doesn't show 2005, 2006, 2007, 2008, 2009. $y_options only show 2009, 2009, 2009, 2009, 2009.

    Same for $m_options. It only show December rather than January to December. My source code is as follow:

    Code: ( php )
    [code=php]
    $array_month = array("1"=>"Jan uary","2"=>"Feb uary","3"=>"Mar ch","4"=>"April ","5"=>"May","6 "=>"June"," 7" =>"July","8"=>" August","9"=>"S eptember","10"= >"October","11" =>"November","1 2"=>"December") ;
    $array_year = array("2005","2 006","2007","20 08","2009");
    $m_options = array();
    while (list($indx,$mt h) = each ($array_month)) {
    $tmp_mth->m_title = $mth;
    $tmp_mth->m_value = "?month=".$indx ."&year=".$year ;
    if ($indx == $month) {
    $tmp_mth->selected = "selected";
    }
    array_push($m_o ptions,$tmp_mth );
    $tmp_mth->selected = "";
    }
    $y_options = array();
    foreach ($array_year as $yr) {
    $tmp_yr->y_title = $yr;
    $tmp_yr->y_value = "?month=".$mont h."&year=".$y r;
    if ($yr == $year) {
    $tmp_yr->selected = "selected";
    }
    array_push($y_o ptions,$tmp_yr) ;
    $tmp_yr->selected = "";
    print_r ($tmp_yr->y_title);
    print_r ($y_options);
    }
    [/code]


    Would appreciate if anybody can help.
Working...