-2

我想从这样的数组中恢复所有值:

$var = array($jogo1_t1, $jogo1_t2, $jogo2_t1, $jogo2_t2, $jogo3_t1, $jogo3_t2);

如何将每个值导出到不同的变量中?

例如:

$var1 = FIRST ARRAY VALUE
$var2 = SECOND ARRAY VALUE
$var3 = THIRD ARRAY VALUE
4

3 回答 3

2

要么使用list()

list($var1, $var2, $var3, $var4, $var5, $var6) = $var;

或者简单地使用数组键:

$var1 = $var[0];
$var2 = $var[1];
$var3 = $var[2];
$var4 = $var[3];
$var5 = $var[4];
$var6 = $var[5];

或者如果你必须,使用动态变量名(如果$var是任何大小,这将工作,而无需重写代码):

for ($i = 0; $i < count($var); $i++) {
    $variableName = 'var' . ($i + 1);
    $$variableName = $var[$i];
}
于 2013-09-24T15:34:01.643 回答
1

你需要 list(): http: //nl3.php.net/manual/en/function.list.php

$array = array($jogo1_t1, $jogo1_t2, $jogo2_t1, $jogo2_t2, $jogo3_t1, $jogo3_t2); list($var1,$var2) = $array;

于 2013-09-24T15:34:59.707 回答
0
$var1 = $var[0];
$var2 = $var[1];
$var3 = $var[2];
// ...etc
于 2013-09-24T15:34:53.220 回答