Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,949 questions

51,891 answers

573 users

How to generate array with string prefixes and zero padding consecutive numbers in PHP

1 Answer

0 votes
// range(string|int|float $start, string|int|float $end, int|float $step = 1): array
 
$array = array_map(function($n) { return sprintf('sample_%03d', $n); }, range(30, 42) );

print_r($array);
   
   
   
   
/*
run:
   
Array
(
    [0] => sample_030
    [1] => sample_031
    [2] => sample_032
    [3] => sample_033
    [4] => sample_034
    [5] => sample_035
    [6] => sample_036
    [7] => sample_037
    [8] => sample_038
    [9] => sample_039
    [10] => sample_040
    [11] => sample_041
    [12] => sample_042
)

*/

 



answered Sep 23, 2023 by avibootz

Related questions

2 answers 61 views
1 answer 101 views
1 answer 70 views
1 answer 67 views
1 answer 64 views
1 answer 67 views
...