samedi 1 avril 2017

Formating numbers with trailing zeros in Blade view

I have the following code in a Blade view:

@for ($i = 1; $i <= 99; $i++)
    <div id="player-"></div>
@endfor

Which generates divs with ids player-1, player-2, player-3, etc. But what I really need is to have the ids player-01, player-02, player-03, etc. Is there a function in blade to do that like printf in PHP? or using a ternary operator is the best way around?

(The ternary operator works fine when only one zero needs to be added, but doesn't work that fine when more zeros are needed)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire