Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么array\u combine不返回数组?_Php_Arrays - Fatal编程技术网

Php 为什么array\u combine不返回数组?

Php 为什么array\u combine不返回数组?,php,arrays,Php,Arrays,当我试图打印从这个函数返回的数组时,我得到一个空白屏幕 我的数组$terms和$definitions的长度相同,它们存在于我调用make_associative_array()之前和之后 美元条款: Array ( [0] => Nock (verb) [1] => End [2] => Serving [3] => Nock (noun) ) $定义: Array ( [0] => To place an arrow against

当我试图打印从这个函数返回的数组时,我得到一个空白屏幕

我的数组
$terms
$definitions
的长度相同,它们存在于我调用
make_associative_array()
之前和之后

美元条款:

Array ( 
     [0] => Nock (verb) [1] => End [2] => Serving [3] => Nock (noun) 
)
$定义:

Array ( 
     [0] => To place an arrow against the string prior to shooting. [1] => A group of arrows shot during a tournament. Usually 6. [2] => Thread wound around a bow string to protect the string. [3] => A notch at the rear of an arrow. The bow string is placed in the nock. 
)

我在您的案例中使用PHP5.6.27

-
array\u combine
返回
NULL
,因为
$terms
$definitions
make\u associative\u array
的范围内都是NULL

function make_associative_array() {
    return array_combine($terms, $definitions);
}

$c = make_associative_array();
print_r($c);
您可以将其设置为全局:

function make_associative_array() {
    global $terms, $definitions;
    return array_combine($terms, $definitions);
}
或将其传递给函数:

function make_associative_array($terms, $definitions) {
    return array_combine($terms, $definitions);
}
$c = make_associative_array($terms, $definitions);
无论如何-我真的建议您打开错误:

在您的情况下-
数组\u combine
返回
NULL
,因为
$terms
$definitions
使数组关联的范围内都为NULL

function make_associative_array() {
    return array_combine($terms, $definitions);
}

$c = make_associative_array();
print_r($c);
您可以将其设置为全局:

function make_associative_array() {
    global $terms, $definitions;
    return array_combine($terms, $definitions);
}
或将其传递给函数:

function make_associative_array($terms, $definitions) {
    return array_combine($terms, $definitions);
}
$c = make_associative_array($terms, $definitions);
无论如何-我真的建议您打开错误:

您必须将参数传递给函数

 <?php
    function make_associative_array($terms,$definitions) {

        return array_combine($terms, $definitions);
    }

    $terms=Array ( 0 => 'Nock (verb)', 1 => 'End', 2=> 'Serving', 3=> 'Nock (noun) '
    );

    $definitions=Array ( 
         0 => 'To place an arrow against the string prior to shooting.' ,1 => 'A group of arrows shot during a tournament. Usually 6.', 2 => 'Thread wound around a bow string to protect the string.' ,3=> 'A notch at the rear of an arrow. The bow string is placed in the nock.' 
    );

    $c = make_associative_array($terms,$definitions);
    echo "<pre>";
    print_r($c);

您必须将参数传递给函数

 <?php
    function make_associative_array($terms,$definitions) {

        return array_combine($terms, $definitions);
    }

    $terms=Array ( 0 => 'Nock (verb)', 1 => 'End', 2=> 'Serving', 3=> 'Nock (noun) '
    );

    $definitions=Array ( 
         0 => 'To place an arrow against the string prior to shooting.' ,1 => 'A group of arrows shot during a tournament. Usually 6.', 2 => 'Thread wound around a bow string to protect the string.' ,3=> 'A notch at the rear of an arrow. The bow string is placed in the nock.' 
    );

    $c = make_associative_array($terms,$definitions);
    echo "<pre>";
    print_r($c);

没有必要重复一个已经存在的答案(你可以投票给现有的答案,你知道…@Dekel)。我没有重复回答。我通过在localhost中执行hist代码给出了答案。如果我们在localhost中退出,并且在发布时需要时间,那么在发布时需要时间。您的答案正是我已经编写的答案。你能解释一下区别吗?@Dekel。对不起。我不想争论。对不起。我已经更新了他的数组字符串并退出并给出了输出。我没有要求op接受或投票我的答案,这是他的利益。这不是这里的问题。。。这不是争论。如果答案已经存在,就没有理由重复。如果你认为你的答案不一样,只需说出它的确切程度。没有必要重复已经存在的答案(你可以投票给现有的答案,你知道…@Dekel)。我没有重复回答。我通过在localhost中执行hist代码给出了答案。如果我们在localhost中退出,并且在发布时需要时间,那么在发布时需要时间。您的答案正是我已经编写的答案。你能解释一下区别吗?@Dekel。对不起。我不想争论。对不起。我已经更新了他的数组字符串并退出并给出了输出。我没有要求op接受或投票我的答案,这是他的利益。这不是这里的问题。。。这不是争论。如果答案已经存在,就没有理由重复。如果你认为你的答案不一样,就说它到底有多准确。