php调用数组从一个函数到另一个函数

时间:2015-02-04 13:06:10

标签: php wordpress

我写了一个wordpress插件,我遇到了一个问题.... 我怎样才能将我的数组$ start从名为inputFraInputtable的函数调用到名为time_registrering的函数中? 下面是我试图调用它的函数以及从

调用它的地方
function time_registrering(){



inputtable_func();
inputFraInputtable(
$date,
$start,
$slut,
$pause,
$egenb,
$tot
);
print_r($start);
echo $start[startA];
}


function time_registrering(){

 function inputFraInputtable() {
if(isset($_POST['submit'])) {
    global $_POST;
$date = array(
    'dateA'=>$_POST['dateA'],
    'dateB'=>$_POST['dateB'],
    'dateC'=>$_POST['dateC'],
    'dateD'=>$_POST['dateD'],
    'dateE'=>$_POST['dateE'],
    'dateF'=>$_POST['dateF'],
    'dateG'=>$_POST['dateG'],
);
    $start = array(
    'startA'=>$_POST['startA'], 
    'startB'=>$_POST['startB'], 
    'startC'=>$_POST['startC'], 
    'startD'=>$_POST['startD'], 
    'startE'=>$_POST['startE'], 
    'startF'=>$_POST['startF'],
    'startG'=>$_POST['startG'],
    );
$slut = array(
    'slutA'=>$_POST['slutA'],
    'slutB'=>$_POST['slutB'],
    'slutC'=>$_POST['slutC'],
    'slutD'=>$_POST['slutD'],
    'slutE'=>$_POST['slutE'],
    'slutF'=>$_POST['slutF'],
    'slutG'=>$_POST['slutG'],
    );
$pause = array(
    'pauseA'=>$_POST['pauseA'],
    'pauseB'=>$_POST['pauseB'],
    'pauseC'=>$_POST['pauseC'],
    'pauseD'=>$_POST['pauseD'],
    'pauseE'=>$_POST['pauseE'],
    'pauseF'=>$_POST['pauseF'],
    'pauseG'=>$_POST['pauseG'],
);
$egenb = array(
    'egenbA'=>$_POST['egenbA'],
    'egenbB'=>$_POST['egenbB'],
    'egenbC'=>$_POST['egenbC'],
    'egenbD'=>$_POST['egenbD'],
    'egenbE'=>$_POST['egenbE'],
    'egenbF'=>$_POST['egenbF'],
    'egenbG'=>$_POST['egenbG'],
);
$tot = array(
    'totA'=>$_POST['totA'],
    'totB'=>$_POST['totB'],
    'totC'=>$_POST['totC'],
    'totD'=>$_POST['totD'],
    'totE'=>$_POST['totE'],
    'totF'=>$_POST['totF'],
    'totG'=>$_POST['totG'],
);
}
}

1 个答案:

答案 0 :(得分:0)

E.g。将该数组作为函数的参数传递

<?php
foo();

function foo() {
    $start = array('x','y','z');

    echo '[', bar($start), ']';
}

function bar(array $items) {
    return join(', ', $items);
}

foo()以某种方式构建一个数组,将它传递给bar(),bar()用它做一些事情并返回一些东西。返回值再次是foo()中的回声。

见:
http://docs.php.net/language.variables.scope
http://en.wikipedia.org/wiki/Dependency_injection