How does PHP generate strings cyclically?

Source: Internet
Author: User
How can I generate a string cyclically in PHP? For example, aa01aa02aa03aa04 ...... aa99: I want to print such a string. how can I implement this? It is best to enable automatic paging for every 10 groups. ------ Solution ------------------ for & nbsp; ($ i1; $ I & lt; 99; $ I ++) {& nbsp; $ arr [] sprintf (beginner's advice on how to generate a string cyclically in PHP?
For example
Aa01
Aa02
Aa03
Aa04
......
Aa99


I want to print such a string. how can I implement it?
It is best to enable automatic paging for every 10 groups.
------ Solution --------------------
for ($i=1;$i<=99;$i++){
$arr[]=sprintf("aa%02d",$i);
}
print_r($arr);

------ Solution --------------------

[Align = left] // string two-dimensional array. each string is a group, that is, every ten strings constitute an array.
$ Strarr = array ();
// Counter, used to calculate the number of array elements in $ strarr
$ Count = 0;
// Generate the desired string array
For ($ I = 1; $ I <= 99; $ I ++ ){
// Every 10 strings are generated, the counter $ count is automatically added to 1
If ($ I-1) % 10 === 0) $ count ++;
// Set 1 ~ Convert numbers within 9 to strings in 0i format
$ Stri = ($ I >=1 & $ I <= 9 )? ('0'. $ I): $ I;
$ Strarr [$ count-1] [] = 'a'. $ stri;
}
Echo'
';
print_r($strarr);
echo '
'; [/Align]

------ Solution --------------------

$arr = array();
for($i=1; $i<100; $i++){
$arr[(int)($i-1)/10][] = sprintf("aa%s", str_pad($i,2,'0',STR_PAD_LEFT));
}
print_r($arr);
?>

------ Solution --------------------
for($i=0; $i<100; $i++) $res[] = sprintf('aa%02d
', $i);
echo join("

\n", array_map('join', array_chunk($res, 10)));

aa00
aa01
aa02
aa03
aa04
aa05
aa06
aa07
aa08
aa09


aa10
aa11
aa12
aa13
aa14
aa15
aa16
aa17
aa18
aa19


aa20
aa21
aa22
aa23
aa24
aa25
aa26
aa27
aa28
aa29


aa30
aa31
aa32
aa33
aa34
aa35
aa36
aa37
aa38
aa39


aa40
aa41
aa42
aa43
aa44
aa45
aa46
aa47
aa48
aa49


aa50
aa51
aa52
aa53
aa54
aa55
aa56
aa57
aa58
aa59


aa60
aa61
aa62
aa63
aa64
aa65
aa66
aa67
aa68
aa69


aa70
aa71
aa72
aa73
aa74
aa75
aa76
aa77
aa78
aa79


aa80
aa81
aa82
aa83
aa84
aa85
aa86
aa87
aa88
aa89


aa90
aa91
aa92
aa93
aa94
aa95
aa96
aa97
aa98
aa99

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.