Use parameters within a Function, please help me
I have a function like this:
function get_articles($cat=1,$numberposts=1);
it can be used:
get_articles(cat=4&numberposts=6);
//will display 6 posts from category 6
then I want to use that function within another function, like this:
function display_cat($new_cat=1,$new_num=1,$othercontent="")
{
get_articles(cat=$new_cat&numberposts=$new_num)
.......
}
Can I pass function like this ?
Re: Use parameters within a Function, please help me
> I have a function like this:
> function get_articles($cat=1,$numberposts=1);
>
> it can be used:
> get_articles(cat=4&numberposts=6);
> //will display 6 posts from category 6
You mean
get_articles(cat=4, numberposts=6);
yes?
> then I want to use that function within another function, like this:
>
> function display_cat($new_cat=1,$new_num=1,$othercontent="")
> {
> get_articles(cat=$new_cat&numberposts=$new_num)
>
> ......
> }
>
>
> Can I pass function like this ?
I think you mean
get_articles($new_cat, $new_num);
And you're not passing a function, you're passing variables. You can't
pass functions in PHP. You could pass objects, but you don't need to
here.
Re: Use parameters within a Function, please help me
> I think you mean
>
> get_articles($new_cat, $new_num);
>
> And you're not passing a function, you're passing variables. You can't
> pass functions in PHP. You could pass objects, but you don't need to
> here.
Thank you very much for your reply.
here is exactly my code:
$article = get_articles(cat=4&numberposts=6);
// then I will extract data from $article
However, I want to pass 2 parametes cat and numberposts from another
function, so I must write another function:
function display_cat($new_cat=1,$new_num=1,$othercontent="")
{
$article=get_articles(cat=$new_cat&numberposts=$new_num)
......
}
My purpose is want to pass $new_cat and $new_num from function
display_cat().
Is is possible ?
Please help me, thank you very much !
Re: Use parameters within a Function, please help me
BabyBlue wrote:
> I have a function like this:
> function get_articles($cat=1,$numberposts=1);
>
> it can be used:
> get_articles(cat=4&numberposts=6);
> //will display 6 posts from category 6
Wrong group?
This is not PHP; the syntax is wrong.
For the correct PHP syntax read the manual:
http://www.php.net/manual/en/functions.arguments.php
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Re: Use parameters within a Function, please help me
..oO(BabyBlue)
>here is exactly my code:
>
>$article = get_articles(cat=4&numberposts=6);
Should be
$article = get_articles(4, 6);
>However, I want to pass 2 parametes cat and numberposts from another
>function, so I must write another function:
>
> function display_cat($new_cat=1,$new_num=1,$othercontent="")
> {
> $article=get_articles(cat=$new_cat&numberposts=$new_num)
Should be
$article = get_articles($new_cat, $new_num);
> }
Micha
Re: Use parameters within a Function, please help me
BabyBlue wrote:
> I have a function like this:
> function get_articles($cat=1,$numberposts=1);
>
> it can be used:
> get_articles(cat=4&numberposts=6);
> //will display 6 posts from category 6
>
> then I want to use that function within another function, like this:
>
> function display_cat($new_cat=1,$new_num=1,$othercontent="")
> {
> get_articles(cat=$new_cat&numberposts=$new_num)
>
> ......
> }
>
>
> Can I pass function like this ?
>
No, you are incorrect. You would call it with:
get_articles(4, 6);
"cat=4&numberposts=6" is strictly an HTML implementation. It's not used
within functions like this.
So in your display_cat function, you would call it with
get_articles($new_cat, $numberposts);
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================