Estoy usando un while loop
$i = 0;
$arr = array();
while($get_key1 = mysql_fetch_assoc($get_key))
{
$busid = $get_key1['busid'];
$get_key2 = mysql_query("select * from `route` where `busid`='$busid'") or die(mysql_error());
while($get_key3 = mysql_fetch_assoc($get_key2))
{
$arr[$i] = $get_key3['routid'];
echo "<pre>";
print_r($arr);
}
echo "<hr/>";
$i++;
}
Este bucle interno da tres valores, 1,3,4
y cuando se repite de nuevo, da valores 1,4
Quiero crear una matriz multidimensional como
array(array(1,3,4),array(1,4))
pero el código anterior da el resultado como:
Array
(
[0] => 1
)
Array
(
[0] => 1
[1] => 3
)
Array
(
[0] => 1
[1] => 3
[2] => 4
)
Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 1
)
Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 1
[4] => 4
)
¿Cómo puedo almacenar los valores a través del bucle while en una matriz multidimensional?
Debe usarlo $i
como matriz externa y dejar que cree el índice de la matriz interna.
while($get_key3 = mysql_fetch_assoc($get_key2))
{
$arr[$i][] = $get_key3['routid']; // simple change
echo "<pre>";
print_r($arr);
}
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras