PHP two-dimensional data sorting, two-dimensional data fuzzy query, php sorting fuzzy query

Source: Internet
Author: User

PHP two-dimensional data sorting, two-dimensional data fuzzy query, php sorting fuzzy query

1. Because a report in the project needs to merge the data of three tables, you can use the PHP Array Function to sort and search the data after table sharding. The array structure after the three tables are merged is as follows:

Array ([0] => Array ([history_id] => 12 [sla_group_id] => 1 [sla_id] =>-1 [create_time] => 1513057695 [tasklog_id] => 12 [tasklog_time] => 13:48:15 [tasklog_name] => window_2008 [tasklog_type] => group immediate scheduling [tasklog_user] => admin [tasklog_status] => 3) [1] => Array ([history_id] => 11 [sla_group_id] => 1 [sla_id] => 1 [create_time] => 1513057563 [tasklog_id] => 11 [tasklog_time] => 13:46:03 [tasklog_name] => centos7_USHARK [tasklog_type] => one-hour backup frequency [tasklog_user] => system automatic [tasklog_status] => 3) [2] => Array ([history_id] => 19 [sla_group_id] => 1 [sla_id] => 98 [create_time] => 1513059714 [tasklog_id] => 19 [tasklog_time] => 14:21:54 [tasklog_name] => huawei_fusion_backup [tasklog_type] => Huawei virtual backup [tasklog_user] => ushark.net [tasklog_status] => 2) [3] => Array ([history_id] => 41 [sla_group_id] => 0 [sla_id] =>-1 [create_time] => 1513069534 [status] => 2 [tasklog_id] => 41 [tasklog_time] => 17:05:34 [tasklog_name] => centos7-11 auto-incrementing non-integer test [tasklog_user] => admin [tasklog_type] => schedule now [tasklog_status] => 2) [4] => Array ([history_id] => 40 [sla_group_id] => 0 [sla_id] =>-1 [create_time] => 1513067574 [status] => 2 [tasklog_id] => 40 [tasklog_time] => 16:32:54 [tasklog_name] => win2008 install MySQL [tasklog_user] => impp. cc [tasklog_type] => Policy backup [tasklog_status] => 2) [5] => Array ([history_id] => 39 [sla_group_id] => 0 [sla_id] =>-1 [create_time] => 1513067399 [status] => 2 [tasklog_id] => 39 [tasklog_time] => 16:29:59 [tasklog_name] => file in Linux [tasklog_user] => ppstorm.com [tasklog_type] => scheduling now [tasklog_status] => 2 ))

 

2. Sorting and searching of two-dimensional arrays

// Http get values $ length = (int) $ this-> input-> get ('length', true); $ start = (int) $ this-> input-> get ('start', true); $ order = trim ($ this-> input-> get ('order', true )); $ sort = trim ($ this-> input-> get ('dir', true); $ search = trim ($ this-> input-> get ('search ', true); // three table data $ vm_group = $ this-> safe-> vm_group_task (); $ vm_tasklog = $ this-> safe-> vm_tasklog (); $ vm_mounts_log = $ this-> safe-> vm_mounts_log (); // Merge data $ Tasklog = array_merge ($ vm_group, $ vm_tasklog, $ vm_mounts_log );//!!! Two-dimensional data search !!! If (! Empty ($ search) {foreach ($ tasklog as $ sk => $ sv) {if (mb_stripos ($ sv ['tasklog _ name'], $ search) ===false & mb_stripos ($ sv ['tasklog _ type'], $ search) ===false & mb_stripos ($ sv ['tasklog _ user'], $ search) === false) {unset ($ tasklog [$ sk]); continue ;}}// total records $ total_record = count ($ tasklog ); // sort switch ($ order) {case 1: $ sort_key = 'tasklog _ name'; break; case 2: $ sort_key = 'tasklog _ type'; break; Case 3: $ sort_key = 'tasklog _ user'; break; case 4: $ sort_key = 'tasklog _ time'; break; case 5: $ sort_key = 'tasklog _ status'; break; default: $ sort_key = 'tasklog _ id'; break;} $ sort_arr = array_column ($ tasklog, $ sort_key ); $ desc_asc = $ sort = 'desc '? SORT_DESC: SORT_ASC; array_multisort ($ sort_arr, $ desc_asc, $ tasklog );//!!! Two-dimensional data sorting !!! // Get the specified length $ output_arr = array_slice ($ tasklog, $ start, $ length );

 

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.