An error with array_push function

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
Cgull
Forum Newbie
Posts: 7
Joined: Wed Apr 09, 2008 6:11 am

An error with array_push function

Post by Cgull »

Hello,

I am trying to push values into an array and I get this error:

Parse error: syntax error, unexpected T_DOUBLE_ARROW in...

My code is (I added the words ERROR HERE on the problem line):

Code: Select all

	function fGetOrders($day, $month, $year)
	{
		require("dbCon.php");
		
		$orders = array();
		$orderDets = array();
		$i = 0;
		
		$order = mysql_query("select * from customer_orders where day = $day and month = '$month' and year = $year") or die(mysql_error());
		
		$numRows = mysql_num_rows($order);

		if($numRows <> 0)
		{
			while($row = mysql_fetch_assoc($order))
			{
				$orders[$i]['name'] = $row['name'];
				$orders[$i]['phone'] = $row['phone'];
				$orders[$i]['time'] = $row['time'];
				$orders[$i]['paid'] = $row['paid'];
				$orders[$i]['comments'] = $row['comments'];
				$order_id = $row['order_id'];
				$orders[$i]['dets'] = array();
			
				$dets = mysql_query("select * from customer_order where order_id = $order_id") or die(mysql_error());
				while($row1 = mysql_fetch_assoc($dets))
				{
					$product = $row1['product'];
					$qty = $row1['qty'];
					
					array_push($orderDets,'product'=>$product,'qty'=>$qty);ERROR HERE
				}
				$i++;
			}
		}
		
		return($orders);
	}
Can someone please help me and tell me what am I doing wrong?

Thank you
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: An error with array_push function

Post by anantha »

in the array_push($orderDets,'product'=>$product,'qty'=>$qty); function...i think you can do like this

array_push($orderDets,array('product'=>$product,'qty'=>$qty));
Cgull
Forum Newbie
Posts: 7
Joined: Wed Apr 09, 2008 6:11 am

Re: An error with array_push function

Post by Cgull »

Of course !!!

:) a bit of a brain freeze there.

Thank you very much
Post Reply