Skip to content

Instantly share code, notes, and snippets.

@dwihujianto
Created December 11, 2017 14:28
Show Gist options
  • Select an option

  • Save dwihujianto/e6ed95ce36f96f64ccd70a2def3782bf to your computer and use it in GitHub Desktop.

Select an option

Save dwihujianto/e6ed95ce36f96f64ccd70a2def3782bf to your computer and use it in GitHub Desktop.
<?php
$number = '1.345.679';
$number = str_replace('.', '', $number);
$output = '';
$length = strlen($number) - 1 ;
for ($i=0; $i <= $length; $i++) {
$o = '';
if ($length - $i > 0) {
$o = str_repeat('0', $length - $i);
}
$output .= $number[$i].$o."\n";
}
echo($output);
<?php
if(isset($argv[1])) {
print_r(fib($argv[1]));
} else {
echo "Masukan angka php ".$argv[0]." <Jumlah angka> ";
}
function fib($n) {
$f1=0;
$f2=1;
$fibList = [0];
for ($i=0; $i<$n; $i++) {
$output = $f1 + $f2;
array_push($fibList, $output);
$f1 = $f2;
$f2 = $output;
}
return $fibList;
}
<?php
if(isset($argv[1])) {
print_r(printPrime($argv[1]));
} else {
echo "Masukan angka php ".$argv[0]." <Jumlah angka> ";
}
function printPrime($n) {
$primeList = [];
for ($i=1; $i <= $n; $i++) {
$counter = 0;
for($x=1; $x <= $i; $x++) {
if($i % $x == 0) {
$counter++;
}
}
if ($counter == 2) {
$primeList[] = $i;
}
}
return $primeList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment