Php 如何从外部while循环访问阵列

Php 如何从外部while循环访问阵列,php,arrays,Php,Arrays,我希望有人能帮我。我使用数组来存储从数据库中提取的值,但我想知道如何从while循环外部访问它们 $lecturers_temp = array(array()); $i = 0; $q2 = "SELECT `uninum` FROM `availabilityindex` ORDER BY `availability`"; $result2 = @mysqli_query($dbcon,$q2); while ($row2 = mysqli_fetch_array ($result2,

我希望有人能帮我。我使用数组来存储从数据库中提取的值,但我想知道如何从while循环外部访问它们

$lecturers_temp = array(array());
$i = 0;

$q2 = "SELECT `uninum` FROM `availabilityindex` ORDER BY `availability`";

$result2 = @mysqli_query($dbcon,$q2);

while ($row2 = mysqli_fetch_array ($result2, MYSQLI_ASSOC)){
    $lecturers = $row2['uninum']; 
    $lecturers_temp = array(array());
    $lecturers_temp[$i][0] = $row2['uninum'];

    echo $lecturers_temp [$i] [0] . "<BR><BR>";
    $i++;

}

//when I try this I get an undefined offset error
echo $lecturers_temp [1] [0];
$讲师_temp=array(array());
$i=0;
$q2=“根据可用性从可用性索引中选择‘uninum’”;
$result2=@mysqli_查询($dbcon,$q2);
而($row2=mysqli\u fetch\u数组($result2,mysqli\u ASSOC)){
$讲师=$row2['uninum'];
$讲师_temp=array(array());
$teachers_temp[$i][0]=$row2['uninum'];
echo$讲师临时职位[$i][0]。“

”; $i++; } //当我尝试此操作时,会得到一个未定义的偏移量错误 echo$讲师临时工[1][0];
由于在while循环中重置了数组,因此出现了该错误。摆脱
$讲师_temp=array(array())进行编码,然后查看是否得到了所需的结果。

由于在while循环中重置了数组,因此出现了该错误。摆脱
$讲师_temp=array(array())进行编码,然后查看是否得到了所需的结果。

由于在while循环中重置了数组,因此出现了该错误。摆脱
$讲师_temp=array(array())进行编码,然后查看是否得到了所需的结果。

由于在while循环中重置了数组,因此出现了该错误。摆脱
$讲师_temp=array(array())并查看是否得到了所需的结果清除数组中存储的所有以前的项。

the
$讲师_temp=array(array())清除数组中存储的所有以前的项。

the
$讲师_temp=array(array())清除数组中存储的所有以前的项。

the
$讲师_temp=array(array())将删除数组中以前存储的所有项。

只需删除
$讲师_temp=array(array())来自
的代码,而
块。为了简化数据,您还可以使用一维数组:

$lecturers_temp = array();

$i = 0;

$q2 = "SELECT `uninum` FROM `availabilityindex` ORDER BY `availability`";

$result2 = @mysqli_query($dbcon,$q2);

while ($row2 = mysqli_fetch_array ($result2, MYSQLI_ASSOC)){
    $lecturers_temp[$i] = $row2['uninum'];

    echo $lecturers_temp[$i] . "<BR><BR>";
    $i++;
}

//when I try this I get an undefined offset error
echo $lecturers_temp [1];
$讲师_temp=array();
$i=0;
$q2=“根据可用性从可用性索引中选择‘uninum’”;
$result2=@mysqli_查询($dbcon,$q2);
而($row2=mysqli\u fetch\u数组($result2,mysqli\u ASSOC)){
$teachers_temp[$i]=$row2['uninum'];
echo$讲师临时职位[$i]。“

”; $i++; } //当我尝试此操作时,会得到一个未定义的偏移量错误 echo$讲师临时工[1];
只需删除
$teachers\u temp=array(array())来自
的代码,而
块。为了简化数据,您还可以使用一维数组:

$lecturers_temp = array();

$i = 0;

$q2 = "SELECT `uninum` FROM `availabilityindex` ORDER BY `availability`";

$result2 = @mysqli_query($dbcon,$q2);

while ($row2 = mysqli_fetch_array ($result2, MYSQLI_ASSOC)){
    $lecturers_temp[$i] = $row2['uninum'];

    echo $lecturers_temp[$i] . "<BR><BR>";
    $i++;
}

//when I try this I get an undefined offset error
echo $lecturers_temp [1];
$讲师_temp=array();
$i=0;
$q2=“根据可用性从可用性索引中选择‘uninum’”;
$result2=@mysqli_查询($dbcon,$q2);
而($row2=mysqli\u fetch\u数组($result2,mysqli\u ASSOC)){
$teachers_temp[$i]=$row2['uninum'];
echo$讲师临时职位[$i]。“

”; $i++; } //当我尝试此操作时,会得到一个未定义的偏移量错误 echo$讲师临时工[1];
只需删除
$teachers\u temp=array(array())来自
的代码,而
块。为了简化数据,您还可以使用一维数组:

$lecturers_temp = array();

$i = 0;

$q2 = "SELECT `uninum` FROM `availabilityindex` ORDER BY `availability`";

$result2 = @mysqli_query($dbcon,$q2);

while ($row2 = mysqli_fetch_array ($result2, MYSQLI_ASSOC)){
    $lecturers_temp[$i] = $row2['uninum'];

    echo $lecturers_temp[$i] . "<BR><BR>";
    $i++;
}

//when I try this I get an undefined offset error
echo $lecturers_temp [1];
$讲师_temp=array();
$i=0;
$q2=“根据可用性从可用性索引中选择‘uninum’”;
$result2=@mysqli_查询($dbcon,$q2);
而($row2=mysqli\u fetch\u数组($result2,mysqli\u ASSOC)){
$teachers_temp[$i]=$row2['uninum'];
echo$讲师临时职位[$i]。“

”; $i++; } //当我尝试此操作时,会得到一个未定义的偏移量错误 echo$讲师临时工[1];
只需删除
$teachers\u temp=array(array())来自
的代码,而
块。为了简化数据,您还可以使用一维数组:

$lecturers_temp = array();

$i = 0;

$q2 = "SELECT `uninum` FROM `availabilityindex` ORDER BY `availability`";

$result2 = @mysqli_query($dbcon,$q2);

while ($row2 = mysqli_fetch_array ($result2, MYSQLI_ASSOC)){
    $lecturers_temp[$i] = $row2['uninum'];

    echo $lecturers_temp[$i] . "<BR><BR>";
    $i++;
}

//when I try this I get an undefined offset error
echo $lecturers_temp [1];
$讲师_temp=array();
$i=0;
$q2=“根据可用性从可用性索引中选择‘uninum’”;
$result2=@mysqli_查询($dbcon,$q2);
而($row2=mysqli\u fetch\u数组($result2,mysqli\u ASSOC)){
$teachers_temp[$i]=$row2['uninum'];
echo$讲师临时职位[$i]。“

”; $i++; } //当我尝试此操作时,会得到一个未定义的偏移量错误 echo$讲师临时工[1];
谢谢Valery,我把它放在一个2D数组中,因为我计划使用另一个维度来存储我想从数据库中提取的其他数据……不过谢谢你的建议!谢谢Valery,我把它放在一个2D数组中,因为我计划用另一个维度来存储我想从数据库中提取的其他数据……不过谢谢你的建议!谢谢Valery,我把它放在一个2D数组中,因为我计划用另一个维度来存储我想从数据库中提取的其他数据……不过谢谢你的建议!谢谢Valery,我把它放在一个2D数组中,因为我计划用另一个维度来存储我想从数据库中提取的其他数据……不过谢谢你的建议!