I've got a record set. Row, how to read all the recordset to form a two-dimensional array.

Source: Internet
Author: User
This post was last edited by qq914260102 on 2013-11-14 10:08:13

For example, I have 100 records in a recordset $row.

for ($k =0; $k <$100; $k + +) {
$arr =array ($a [$k], $b [$k], $c [$k]);
Print_r ($arr);
}
I can now put these 100 loops out, is 100 a only array, I now want to turn this into a two-dimensional array, write hair.


Reply to discussion (solution)

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

$array 1 = Array (' 1 ', ' 2 ', ' 3 '), $array 2 = Array (' 1 ', ' 2 ', ' 3 '), $arr = Array (); for ($k =0; $k <100; $k + +) {//This is not $100$arr[]= Array ($array 1[$k], $array 2[$k]);} echo "
";p Rint_r ($arr);

I'll go. Color added wrong.

$array 1 = Array (' 1 ', ' 2 ', ' 3 '), $array 2 = Array (' 1 ', ' 2 ', ' 3 '), $arr = Array (); for ($k =0; $k <100; $k + +) {$arr []=array ($ array1[$k], $array 2[$k]);} echo "
";p Rint_r ($arr);

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

I just finished it, and I found this method most convenient.

For example, I have 100 records in a recordset $row.

for ($k =0; $k <$100; $k + +) {
$arr =array ($a [$k], $b [$k], $c [$k]);
Print_r ($arr);
}
I can now put these 100 loops out, is 100 a only array, I now want to turn this into a two-dimensional array, write hair.

As the result of the above output is
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)

I want the result of this. ,
is $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)

You're talking about a two-dimensional array.

foreach ($row as $val) {    print_r ($val);}

You're talking about a two-dimensional array.

foreach ($row as $val) {    print_r ($val);}


Specific code.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.