Multi-level queries in PHP are recursive and iterative in a detailed way

Source: Internet
Author: User

Now the mall class app or shopping site generally in addition to shopping, but also played a role in promotion, publicity and distribution, multi-level query is generally used in recursive and circular way. However, many beginners are not clear how to achieve, the following is a 20-level example, the code and run the results are as follows:
1.PHP query for each level number.
The PHP code is as follows:
$aim ["Prevtel"] = $tel;

    $n=0;    $array_co = array();    while ( $n< 10) {         $users=M(‘user‘)->where($aim)->getField(‘tel‘,true);         $aims[‘prevtel‘] = array(‘in‘,$users);          $array_co[] = count($users)."";          $user2=M(‘user‘)->where($aims)->getField(‘tel‘,true);        $array_co[] = count($user2)."";         $aim[‘prevtel‘] = array(‘in‘,$user2);              $n++;    }  return $array_co;

2.php querying each level of personal information
The PHP code is as follows:
$aim ["prevtel"] = ' 15639743913 ';

    $n=0;    $array_co = array();    while ( $n< 10) {         $users=M(‘user‘)->where($aim)->select();         $users1=array();         foreach ($users as $key => $value) {           $users1[]=$value[‘tel‘];         }         $aims[‘prevtel‘] = array(‘in‘,$users1);          $array_co[] = $users;          $user2=M(‘user‘)->where($aims)->select();          $users2=array();          foreach ($user2 as $k => $v) {           $users2[]=$v[‘tel‘];         }        $array_co[] = $user2;         $aim[‘prevtel‘] = array(‘in‘,$users2);              $n++;    }  var_dump($array_co);

Well, to this end, if you follow the test run, you should see the results, that more levels of the query is the same truth, if you still have questions, you can leave a message to consult, we can discuss mutual learning and progress.

This article by the Professional Zhengzhou app development company Brigitte Xuan Science and Technology finishing release, original is not easy, if need reprint please indicate source!

Multi-level queries in PHP are recursive and iterative in a detailed way

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.