PHP array format output problem, ask the great God

Source: Internet
Author: User
I have one of the following tables


Excuse me, how can I get him to output the following array format according to type and typeid? Thank you

Array (  [0] = Array (            [0]=>            [1]=> Wedding service            [2]=> Machinery Equipment            [3]=> Hospital Medical            [4]=> Lighting            [5]=> Education and training            [6]=> Chemical paint            [7]=> Beauty fitness            [8]=> food            [9]=> Car service            ) [1] = = Array (            [0]=>            [1]= > General            [2]=> two columns            [3]=> three columns            [4]=> grid            ))


Reply to discussion (solution)

Read after query

while ($row = Mysql_fetch_assoc ($rs)) {  $res [$row [' type '] [] = $row [' Typevalue '];} $res = Array_values ($row);

Read after query

while ($row = Mysql_fetch_assoc ($rs)) {  $res [$row [' type '] [] = $row [' Typevalue '];} $res = Array_values ($row);



Xuzuning Moderator, I tried the next page error OH. $res [$row [' type '] [] parentheses here, removing or making an error.

Ruled out the discovery is this error, $res = Array_values ($row); What is the reason for this?

Oh, it's a missing bracket.
$res [$row [' type '] [] = $row [' Typevalue '];

Oh, it's a missing bracket.
$res [$row [' type '] [] = $row [' Typevalue '];



Xuzuning Moderator, change to your latest this, or will page error. Hint is this sentence, error, do not know what is the reason $res = Array_values ($row);

Hint error is warning:array_values () expects parameter 1 to is array, boolean given in

This line is pointed to $res = Array_values ($row);

It's my fault!
$res = Array_values ($res);

Oh, it's a missing bracket.
$res [$row [' type '] [] = $row [' Typevalue '];


-----------------------------------
Fix the xuzuning moderator, is $res = Array_values ($row); Here is the wrong, $row out of the array is not an error, has been changed, thank you for your ideas.

It's my fault!
$res = Array_values ($res);


It's done. (*^__^*) hehe ... Thank you
  • 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.