array_push problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grace01
Forum Newbie
Posts: 5
Joined: Wed Sep 05, 2007 3:43 am

array_push problem

Post by grace01 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,

I migrated a php website from another hosting company. When the website is running on our server, I encounter a problem. I want to display year and month on the php webpage. After run array_push($y_options,$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 12 December rather than January to December. My source code is as follow:

Code: Select all

$array_month = array("1"=>"January","2"=>"Febuary","3"=>"March","4"=>"April","5"=>"May","6"=>"June","7"=>"July","8"=>"August","9"=>"September","10"=>"October","11"=>"November","12"=>"December");
$array_year = array("2005","2006","2007","2008","2009");
$m_options = array();
while (list($indx,$mth) = 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_options,$tmp_mth);
	$tmp_mth->selected = "";
}
$y_options = array();
foreach ($array_year as $yr) {
	$tmp_yr->y_title = $yr;
	$tmp_yr->y_value = "?month=".$month."&year=".$yr;
	if ($yr == $year) {
		$tmp_yr->selected = "selected";
	}
	array_push($y_options,$tmp_yr);
	$tmp_yr->selected = "";
print_r ($tmp_yr->y_title);
print_r ($y_options);
}
Would appreciate if anybody can help.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
playgames
Forum Newbie
Posts: 22
Joined: Tue Sep 04, 2007 4:28 am

Post by playgames »

oddball. may be you server has something incrot . and PHP SET LOSTED

try to remake you php :lol:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Use the correct

Code: Select all

tags to make the error easier to find.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: array_push problem

Post by volka »

please try

Code: Select all

erro_reporting(E_ALL);
ini_set('display_errors', true);
$array_month = array("1"=>"January","2"=>"Febuary","3"=>"March","4"=>"April","5"=>"May","6"=>"June","7"=>"July","8"=>"August","9"=>"September","10"=>"October","11"=>"November","12"=>"December");

...
Post Reply