Ask another question about the PHP array format.

Source: Internet
Author: User
Ask another question about the PHP array format. Thanks for answering the previous array question xuzuning. I want to ask another question. can I do this if I put the type value in the table into the array?





Use the above table to implement the following array

Array ([classname] => 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) [layout] => array ([0] => [1] => regular [2] => two columns [3] => three columns [4] => grid ))


Reply to discussion (solution)

In my words, $ res is the format you want now.
This post requires a subscript array.
$ Res = array_values ($ res );

$classname="select * from table where type='classname'";$layout="select * from table where type='layout'";

In my words, $ res is the format you want now.
This post requires a subscript array.
$ Res = array_values ($ res );




Xuzuning I just tried it out. thank you, that is, the format $ res is used. there is another problem, what if I want to replace the "unlimited" word with a null value when I want to output it?

In all your previous descriptions, there are no "unlimited" words.


In all your previous descriptions, there are no "unlimited" words.



Sorry, I just found that the uploaded graph data is old. The typevalue of type = 0 is "unlimited ". Or is that okay? It is how to replace the typevalue of the corresponding row with a null value when type = 0 in the output result of the array.

While ($ row = mysql_fetch_assoc ($ rs )){
If ($ row ['typeid'] = 0) $ row ['typevalue'] = '';
$ Res [$ row ['type'] [] = $ row ['typevalue'];
}

While ($ row = mysql_fetch_assoc ($ rs )){
If ($ row ['typeid'] = 0) $ row ['typevalue'] = '';
$ Res [$ row ['type'] [] = $ row ['typevalue'];
}



Thank you very much.

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.