HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpMinor

Get number from N

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
numberfromget

Problem

I'm trying to find the shortest and best way to achieve the following:

Given input integer $N, get the following output:

  • n = 0, output = 0



  • n = 1, output = 0



  • n = 2, output = 10



  • n = 3, output = 100



  • n = 4, output = 1000



  • n = 5, output = 10000



I do this with the following code, but there must be a better option to do this.

Solution

The pow function is probably what you are looking for.

return pow(10, $n-1); should be close to what you want but might need tweeking for borderline cases.

Context

StackExchange Code Review Q#123867, answer score: 5

Revisions (0)

No revisions yet.