470,866 Members | 1,930 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,866 developers. It's quick & easy.

PHP Function- Help Please

I'm trying to generate an array for a price selection box and i keep
getting this error on the php page:

"Parse error: parse error, expecting `'('' in
/var/www/html/site/index.php on line 13"

Line 13 refers to "array_name= array["0"];" line.
I've tried:

-"array_name= array("0");"

Could someone help, the code is below.
function price_array($array_name){
$array_name= array["0"]; //declare array
for ($i=0;$i <= 10000000;$i=$i+100000){
$array_name = array_push($array_name,"$i");
}
return $array_name;
}

//call
$smarty->assign('sell_price1', array (price_array('price_from')));
Jul 17 '05 #1
1 1706
jpastora wrote:
I'm trying to generate an array for a price selection box and i keep
getting this error on the php page:

"Parse error: parse error, expecting `'('' in
/var/www/html/site/index.php on line 13"

Line 13 refers to "array_name= array["0"];" line.
I've tried:

-"array_name= array("0");"

Could someone help, the code is below.
function price_array($array_name){ You don't need to pass the array name to the function.
$array_name= array["0"]; //declare array Bad syntax
for ($i=0;$i <= 10000000;$i=$i+100000){
$array_name = array_push($array_name,"$i"); array_push() returns an integer.
This line assigns 1 to $array_name;
the next time through the loop it will try to add an element to
$array_name which /is not/ an array!
Please see the manual: http://www.php.net/array_push
}
return $array_name;
}
I'd do that like this:

function price_array() {
$local_array = array(); // initialize local array
for ($i = 0; $i <= 10000000; $i += 100000) {
$local_array[] = $i;
}
return $local_array;
}
//call
$smarty->assign('sell_price1', array (price_array('price_from')));


and call it like this (I'm copying your syntax -- never used
smarty -- it may be wrong):

$smarty->assign('sell_price1', price_array());
HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by domeceo | last post: by
2 posts views Thread by laredotornado | last post: by
2 posts views Thread by sushil | last post: by
8 posts views Thread by Olov Johansson | last post: by
3 posts views Thread by Beta What | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.