Let me help you to understand the meaning of "%" in this code-php Tutorial

Source: Internet
Author: User
Let's take a look at what "%" means in this code $ col4; $ index0; $ pai_displayarray (); foreach ($ pai_listas $ share) {$ mod $ index % $ col; $ pai_display [col. $ mod] [] $ share; let's take a look at the meaning of "%" in this code.
$ Col = 4;
$ Index = 0;
$ Pai_display = array ();
Foreach ($ pai_list as $ share)
{
$ Mod = $ index % $ col;
$ Pai_display ['col'. $ mod] [] = $ share;
$ Index ++;
}

I don't quite understand. it seems like this code means that the array is divided into four sub-arrays by The Shard _list and assigned to the Shard _display.

------ Solution --------------------
$ Index % $ col get $ index divided by the remainder of $ col
------ Solution --------------------
Remainder'
------ Solution --------------------
Do you have never learned to calculate the remainder?
------ Solution --------------------
Yes, the array $ arrays _list is scattered into four sub-arrays.
------ Solution --------------------
Discussion

I checked it and said it was a modulo operator. However, the result of the value I got is $ pai_display ['col'. $ mod] []. only col has four items.

In this case, the value of $ mod has always been in the 0123 loop, but there are a total of 40 values under $ Every _list, and the values from 40 to 4 are all counted as 10.

------ Solution --------------------
Remainder 3
------ Solution --------------------
All the arithmetic problems in elementary school are called remainder!
------ Solution --------------------
The modulo operation is to calculate the remainder.

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.