I have a variable $doctype
that is an array:
$doctype = array(
'news' => ('news'),
'documents' => ('documents'),
'forms' => ('forms'),
'other' => ('other'),
);
which is used as options for another array:
$form['doc_type'] = array(
'#title' => 'Document Type',
'#type' => 'radios',
'#options' => $doctype,
'#size' => '30',
'#required' => TRUE,
'#default_value' => $doctype['news'],
now I'm trying to pass the current value for another function
I've tried:
form($form_state, &$doctype) {
but it shows up as a missing argument
I want to pass it through a reference, not as a return (already occupied/don't want to work around it)
Any help is appreciated
Assuming form()
specifies its second argument as a reference, then you shouldn't pass &$doctype
as a parameter. If the function specifies a parameter as a reference, then all you need to do is pass that variable and it will get passed as a reference.
E.g.
<?php
function form($var1, &$var2) {
$var2[2] = 5;
}
$var2 = array(1,2,3,4);
form('test', $var2);
echo $var2[2]; // Echoes '5';
?>
However, I'm again assuming that form()
is built into drupal, in which case as far as I know there's no way of passing $doctype
as a reference without changing the core code that defines form()
Out of curiosity, why do you need to pass it as a reference? Can you clarify "already occupied/don't want to work around it"