The problem of mod value in Volist cycle in thinkphp

Source: Internet
Author: User

<ul>    Key= "K" mod= "2" >        <eq name= "mod" value= "0" >            <li>{$k} ... {$arr. ID}---{$arr. User}---{$arr.email}</li>        </eq>    </volist ></ul>

The values taken are:

    • 1...1---lu Fei [email protected]
    • 3...3---Crayon [email protected]
    • [Email protected]
    • 7...65---Be careful [email protected]
    • 9...74---aa73f80eb8608a88a135---
    • 11...76---_ hehe [email protected]
    • [Email protected]

Why is the value taken out like this? According to its own understanding should be $mod = $k% 2; Then for the output of 0, how $k is the cardinality, should not be an even number?

Then look at the source code in the cache:

<ul> <?phpif(Is_array($data)):$k= 0; $__list__=$data; if(Count($__list__) = = 0):Echo""; Else:foreach($__list__  as $key=$arr):$mod= ($k% 2); ++$k; if(($mod) = = "0"):?> <li><?phpEcho($k);? >...<?phpEcho($arr["id"]); ?>---<?phpEcho($arr["User"]); ?>---<?phpEcho($arr["email"]); ? ></li><?phpendif;Endforeach;endif; Else:Echo"";endif;?></ul>

Yes, $k started from 0, and the outside $k was 1.

We do this by defining ourselves as a $i:

<ul>    <!--take mod questions--    <php>$i=0;</php>    Key= "K" mod= "5" >        <eq name= "mod" value= "0" >            <li><php>echo$i; </php> {$arr. ID}---{$arr. User}---{$arr.email}</li>        </eq>        <php >$i++;</php>    </volist></ul>

Value:

    • 0...1---lu Fei [email protected]
    • 2...3---Crayon [email protected]
    • [Email protected]
    • 6...65---Be careful [email protected]
    • 8...74---aa73f80eb8608a88a135---
    • 10...76---_ hehe [email protected]
    • [Email protected]

The answer is clearly out, it is thinkphp in the MoD $k value changed ....

The problem of mod value in Volist cycle in thinkphp

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.