-1

My function is like this:

<?php
function facebook_friend_list($username){
............................................
............................................
echo "Number of friends:". $N ;
}
?>

My problem: I have to call This function like this :

facebook_friend_list($a);
facebook_friend_list();
facebook_friend_list($t);
............................
............................

inside a loop. So, sometimes this function is getting parameter and sometimes it is not getting. When it does not get parameter, it shows "Missing argument 1 for facebook_friend_list(), called in........................................................."

How to solve this problem?

3
  • Assign a default value to your parameter like function facebook_friend_list($username = '') or whatever default value you need Commented Jan 11, 2015 at 6:32
  • 1
    Can your function handle an empty string or NULL as parameter? If so, explicitly pass that, or make it the default param value in the function declaration. See php.net/manual/en/… Commented Jan 11, 2015 at 6:32
  • 1
    Why do you have to call the function without arguments? What is the meaning of "asking for the friend list of <nobody>" ? Commented Jan 11, 2015 at 6:33

4 Answers 4

1
<?php

  function facebook_friend_list($username = null){

    if($username == null){
         // argument is not given stuff 
    }

    if($username != null){
         // argument is gived to access use :-  echo $username;
    }

    ............................................
    ............................................
   echo "Number of friends:". $N ;
 }

?>

Thanks :)

Sign up to request clarification or add additional context in comments.

Comments

0

You really ought to tell us more about what you're trying to accomplish, but you can make parameters optional by specifying defaults:

function facebook_friend_list($username = null) {
    ...
}

Comments

0

Change the line

function facebook_friend_list($username){

to

function facebook_friend_list($username = '') {

Then, within the function facebook_friend_list(), make sure to add code to handle the situation when the string is empty.

You can also use a value other than a default string, for example if you wanted it to use a certain username by default, you could type this instead:

function facebook_friend_list($username = "exampleusername") {

Comments

0

try this ,

inside the loop
  if($var != null){
		facebook_friend_list($var);
  }else{
		assign 0 ;
  }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.