LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2004, 10:01 PM   #1
Parksy
Member
 
Registered: Apr 2003
Distribution: Gentoo/Mandrake 10.0
Posts: 110

Rep: Reputation: 15
Arguments in PHP function declaration


I'm not very good with php but I'm trying to modify a cpgnuke module. I'm writing a new function that looks like this:

Code:
function drawbox($title, $content, $boxid, $btn[0], $btn[1] ) { code in here }
However, because of the array stuff, I get this error:

Code:
Parse error: parse error, expecting `')'' in file.php on line xxx
When I call the function, I want to put each array element in as an argument (there will be more than just the two elements of the array). I need to use arrays because of what I do inside the function.

I've tried looking at the online php manuals, but I don't really know what I'm looking for.
 
Old 07-03-2004, 03:31 AM   #2
hylke
Member
 
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329

Rep: Reputation: 30
Re: Arguments in PHP function declaration

Quote:
Originally posted by Parksy
Code:
function drawbox($title, $content, $boxid, $btn[0], $btn[1] ) { code in here }
If that's the decelaration, i think that's the problem.
You should change it in:
Code:
function drawbox($title, $content, $boxid, $btn1, $btn2 ) { code in here }
 
Old 07-03-2004, 03:37 PM   #3
Parksy
Member
 
Registered: Apr 2003
Distribution: Gentoo/Mandrake 10.0
Posts: 110

Original Poster
Rep: Reputation: 15
Is there no way to put an array in the declaration? What I plan to do is put constants (numbers/strings) in when I call the function, but then have the function use those as parts of an array. I guess I could do this:
PHP Code:
$btn[0] = $btn1
$btn
[1] = $btn2 
for all the elements I want to put into the array, then manipulate the $btn[] array. I will try it to see if it works. It that the only way to do it?

What the function is doing is making up to three javascript anchors in a box. I want to do a 2d array where one column is the anchor text (<a>textthatgoeshere</a>)and the other column is an argument for the javascript function. I'm going to do a while loop so that anchors are created while the anchor text is not 0. That way I can use the function to make 1, 2 or 3 anchors (or more if I make a bigger array and have more function arguments). I figure the easiest way to do this is with an array.
 
Old 07-03-2004, 09:02 PM   #4
Parksy
Member
 
Registered: Apr 2003
Distribution: Gentoo/Mandrake 10.0
Posts: 110

Original Poster
Rep: Reputation: 15
Here's what I ended up doing. It works fine, but it still seems a little ugly.

PHP Code:
function drawbox($title$content$boxid$btn1$btn2$btn3$btn4$btn5$btn6) {
$btn[1][0] = $btn1;
$btn[1][1] = $btn2;
$btn[2][0] = $btn3;
$btn[2][1] = $btn4;
$btn[3][0] = $btn5;
$btn[3][1] = $btn6;
//rest of function

 
Old 07-04-2004, 09:42 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Why do younot call your function with an array like :

PHP Code:
function drawbox$title$content$boxid$btn ) {
//rest of function
}

$btn = Array();
$title "something";
$content "something";
$boxid "something";

/* code to fill $btn array with values ... */

//call to drawbox function...
drawbox$title$content$boxid$btn ); 
 
Old 07-04-2004, 04:22 PM   #6
Parksy
Member
 
Registered: Apr 2003
Distribution: Gentoo/Mandrake 10.0
Posts: 110

Original Poster
Rep: Reputation: 15
Yeah that should work the same. I guess it's just a decision of whether to have the extra lines in the drawbox() function or the main function.

Thanks for the idea.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
warning: implicit declaration of function liguorir Linux - Software 5 10-22-2012 03:20 PM
implicit declaration of function 'getdelim' MicahCarrick Programming 2 05-02-2005 11:03 AM
Array declaration in class or main function??? redhatrosh Programming 4 03-15-2005 02:13 PM
Unintelligible declaration of signal function Nerox Programming 4 08-11-2004 04:45 PM
Problem with function declaration Linh Programming 3 04-26-2004 04:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration