我活得了一个记录集row,怎么把所有的记录集读取出来组成一个二维数组。

WBOY
Release: 2016-06-23 14:27:12
Original
794 people have browsed it

本帖最后由 qq914260102 于 2013-11-14 10:08:13 编辑

比如我一个记录集$row 里面有一百条记录。

for($k=0;$k $arr=array($a[$k],$b[$k],$c[$k]));
print_r($arr);
}
我现在可以把这一百条循环出来,是一百个一唯数组,我现在想把这个变成一个二维数组,求写发。。


回复讨论(解决方案)

for($k=0;$k<$100;$k++){   $arr[]=array($yid[$k],$title[$k],$link[$k]));   print_r($arr);}
Copy after login

$array1 = array('1','2','3');$array2 = array('1','2','3');$arr = array();for($k=0;$k<100;$k++){//此处不是$100	$arr[]=array($array1[$k],$array2[$k]);}echo "<pre class="brush:php;toolbar:false">";print_r($arr);
Copy after login

我去。颜色加错咯。

$array1 = array('1','2','3');$array2 = array('1','2','3');$arr = array();for($k=0;$k<100;$k++){	$arr[]=array($array1[$k],$array2[$k]);}echo "<pre class="brush:php;toolbar:false">";print_r($arr);
Copy after login

while $row
{
$arr[$row["id"]]=$row["name"];
}

我刚刚写完 发现这种方法最方便

比如我一个记录集$row 里面有一百条记录。

for($k=0;$k<$100;$k++){
$arr=array($a[$k],$b[$k],$c[$k]));
print_r($arr);
}
我现在可以把这一百条循环出来,是一百个一唯数组,我现在想把这个变成一个二维数组,求写发。。

按照上面输出的结果是
Array ( [0] => a1 [1] => b1 [2] => c1 )
Array ( [0] => asdf2 [1] => b2df [2] => b2sd )
Array ( [0] => a3 [1] => b3 [2] => b6 )
Array ( [0] => a4 [1] => b4 [2] => sdfs )

我想要这样子的结果。,
是$test=Array ( [0] => a1 [1] => b1 [2] => c1 ) ,Array ( [0] => asdf2 [1] => b2df [2] => b2sd ) ,Array ( [0] => a3 [1] => b3 [2] => b6 ),Array ( [0] => a4 [1] => b4 [2] => sdfs )

你说的是要二维数组。

foreach($row as $val){    print_r($val);}
Copy after login
Copy after login

你说的是要二维数组。

foreach($row as $val){    print_r($val);}
Copy after login
Copy after login


求具体代码。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template