Skip to content

Instantly share code, notes, and snippets.

@451F
Created July 5, 2017 19:38
Show Gist options
  • Select an option

  • Save 451F/9cf7510145cd23dd7fe7e9e7398f312b to your computer and use it in GitHub Desktop.

Select an option

Save 451F/9cf7510145cd23dd7fe7e9e7398f312b to your computer and use it in GitHub Desktop.
<?php
$input_array = [
'Hello World',
'lorem ipsum'
];
function reverse_line($line) {
return implode(' ', array_reverse(explode(' ', $line)));
}
foreach ($input_array as $value) {
var_dump(reverse_line($value));
}
<?php
$input = [
[2, 3, 8],
[5, 3, 10]
];
function answers(array $numbers) {
$line_result = '';
for ($i=1;$i<=$numbers[2];$i++) {
if ($i % $numbers[0] === 0) {
if ($i % $numbers[1] === 0) {
$line_result.= ' pingpong';
} else {
$line_result.= ' ping';
}
} elseif ($i % $numbers[1] === 0) {
$line_result.= ' pong';
} else {
$line_result.= ' ' . (string) $i;
}
}
return trim($line_result);
}
foreach ($input as $value) {
var_dump(answers($value));
}
<?php
$input = [2, 3, 4, 5];
function bin_ones_sum($value) {
$str_presentation = '';
for ($i=1;$i<=$value;$i++) {
$str_presentation.= (string) decbin($i);
}
return substr_count(trim($str_presentation), '1');
}
foreach ($input as $value) {
var_dump(bin_ones_sum($value));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment