How to write the function's return?

function annotate_menu() {$items['admin/settings/annotate'] = array('title' => 'Annotation settings','description' => 'Change how annotations behave.','page callback' => 'drupal_get_form','page arguments' => array('annotate_admin_settings'),'access arguments' => array('administer site configuration'),'type' => MENU_NORMAL_ITEM,'file' => 'annotate.admin.inc',);return $items;}

function annotate_admin_settings() {$options = node_get_types(‘names’);$form[‘annotate_node_types’] = array(‘#type’ => ‘checkboxes’,‘#title’ => t(‘Users may annotate these content types’),‘#options’ => $options,‘#default_value’ => variable_get(‘annotate_node_types’, array(‘page’)),‘#description’ => t(‘A text field will be available on these content types tomake user-specific notes.’),);return system_settings_form($form);}

On the above are two functions and each have a return value. but the return value are all irregularly, now if i want to design a function how to write the function’s return.

i want to know why on the above the function’s return line are “return $items” and “return system_settings_form($form)”, could i instead of it using others?
eg:return system_settings_form($form)", i use this “return $form” to place of it.

what I think you mean, is that you’re confused by the two differing ways of return in those two cases?

If that’s it, don’t be. return $items returns the value of the variable $items (in your case an array). And you need to understand that system_settings_form is just another function called within this function, you pass on a variable to that function and as a result it passes another variable back to this function. So basically, it’s the same as saying

$system_settings = system_settings_form($form);
return $system_settings;

Edit, didn’t see Zarin Denatrose’s post, which explains it much better with examples than I did.

Alright, due to the fact that your question has the clarity of a puddle of muck, this may not be the answer you’re looking for. I will, however, take a whack at this.

A return value can be anything that can be stored in a variable. It will be sent back to the line of code that called it, and be put in the place of the calling statement.

Any function with a return can be placed on the right side of a variable assignment to store the returned value.

You can place nearly anything in a return statement as long as it has a value.

Example:


function product($a, $b)
{
  return $a*$b; // returns the result of this mathematical operation.
}

function square($a)
{
  return product($a, $a); //Calls product(), and returns the value that it recieves
}

$number = 2;

echo square($number); //Echo's 4
$numberSquared = square($number); // Sets $numberSquared to 4
echo product(square(3), $numberSquared); // Echo's 36. Square function does 3*3, returns 9, product(9, 4) returns 36, which is then echo'd.

I hope this helps!

guid…
how to write the part of the return value. eg:the above is return $items, return system_settings_form($form);

What do you mean?

Hi,

I know what you mean, you can achieve that with comments in php

example:

/**
 *
 * @return Array 
 */
function test()
{
    return array();
}

so when you have return type you will have all intellisense related to that object

example

class trilli
{
 /**
 * @return trilli
*/
 public function get()
 {
    return $this;
 }
}

$obj = new trilli();
$obj->get()->get()->get();
/*code above will be offered in autocomplete */

Hey,

Do you know how I can include my forum signature in posts by chance? :slight_smile: