Ali Nouman
Ali Nouman

Reputation: 3414

Math Table in php?

I want to get table value in php array.

 $values=array(2,4,6,8,10,12,14,16,18,19,20);

I tried something like this

<?php
 for($i=1;$i<=10;$i++)
 {
$values[]=2*$i;
 }

 ?>

Can i do better may be through some built in functions or some another technique.

Upvotes: 0

Views: 166

Answers (2)

Harsh
Harsh

Reputation: 2096

Try this

$n=2; range($n, $n*10, $n);

Upvotes: 0

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146490

Assuming that 19 is a typo:

$values = range(2, 20, 2);

Upvotes: 4

Related Questions