PHP 8.5.0 Alpha 1 available for testing

Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

ktamas77 at gmail dot com
12 years ago
if you need zero padding, string prefixes or any other masks, then a simple combination of array_map, inline functions and sprintf is your friend.

<?php

$a
= array_map(function($n) { return sprintf('sample_%03d', $n); }, range(50, 59) );

print_r($a);

?>

Will result:

Array
(
[0] => sample_050
[1] => sample_051
[2] => sample_052
[3] => sample_053
[4] => sample_054
[5] => sample_055
[6] => sample_056
[7] => sample_057
[8] => sample_058
[9] => sample_059
)

<< Back to user notes page

To Top