duansha7453 2013-06-21 00:04
浏览 33
已采纳

传递当前数组作为参考[PHP / Drupal6]

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

  • 写回答

1条回答 默认 最新

  • duan198299 2013-06-21 00:14
    关注

    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"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机