Php array format output.

Source: Internet
Author: User
Php array format output question, ask the gods I have the following table


How can I let him output the following array format based on the type and typeid? Thank you.

Array ([0] => array ([0] => [1] => wedding service [2] => mechanical equipment [3] => hospital medical service [4] => lighting and lighting [5] => education and training [6] => chemical coatings [7] => beauty and fitness [8] => catering and food [9] => Car Services) [1] => array ([0] => [1] => regular [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 to report an error on the page. $ Res [$ row ['type'] [] here there are multiple brackets. If this parameter is removed, an error occurs.

The error is ruled out. $ res = array_values ($ row); why?

Oh, there is a bracket missing.
$ Res [$ row ['type'] [] = $ row ['typevalue'];

Oh, there is a bracket missing.
$ Res [$ row ['type'] [] = $ row ['typevalue'];



If the xuzuning moderator is changed to your latest version, a page error occurs. The error message is as follows: $ res = array_values ($ row );

Error message: Warning: array_values () expects parameter 1 to be array, boolean given in

This line points to $ res = array_values ($ row );

My fault!
$ Res = array_values ($ res );

Oh, there is a bracket missing.
$ Res [$ row ['type'] [] = $ row ['typevalue'];


-----------------------------------
After the xuzuning moderator is completed, it is $ res = array_values ($ row); here it is wrong. The $ row is not an array, so it will cause an error. it has been changed. thank you for your ideas.

My fault!
$ Res = array_values ($ res );


Done. (* ^__ ^ *) Xi ...... 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.