This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function matrix($n) | |
{ | |
$result = []; | |
for ($i = 0; $i < $n; $i++) { | |
array_push($result, range(0, $n - 1)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pyramid($n, $row = 0, $content = '') | |
{ | |
$total_column = 2 * $n - 1; | |
$total_content = strlen($content); | |
if ($row === $n && $total_column === $total_content) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pyramid($n) | |
{ | |
$total_column = 2 * $n - 1; | |
for ($row = 0; $row < $n; $row++) { | |
$from = $n - $row - 1; | |
$to = $n + $row - 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function steps($n, $row = 0, $content = '') | |
{ | |
if ($n === $row) { | |
return; | |
} | |
if (strlen($content) === $n) { | |
echo $content . '<br>'; | |
return steps($n, $row + 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function capitalize($string) | |
{ | |
for ($i = 0; $i < strlen(trim($string)); $i++) { | |
if ($i == 0) { | |
$string[$i] = strtoupper($string[$i]); | |
} | |
if ($string[$i] == ' ') { | |
$string[$i+1] = strtoupper($string[$i+1]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Solution 1 | |
function chunk($data, $size) | |
{ | |
$step = 0; | |
$result = []; | |
foreach($data as $i => $v) { | |
$result[$step][] = $v; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reverseInt(_ value: Int) -> Int { | |
let x = value >= 0 ? 1 : -1 | |
return Int(String((String(abs(value))).reversed()))! * x | |
} | |
print(reverseInt(200)) | |
print(reverseInt(25)) | |
print(reverseInt(-15)) | |
print(reverseInt(-90)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
class VirtualHost | |
def initialize (hostPath, vhostPath, projectPath, serverPath, project, domain) | |
@hostPath = hostPath | |
@vhostPath = vhostPath | |
@projectPath = projectPath | |
@serverPath = serverPath | |
@project = project | |
@domain = domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = []; | |
var_dump(count($array)); | |
$arrayObj = new ArrayObject(); | |
var_dump(count($arrayObj)); | |
// Hasil: | |
// int(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Regular | |
{ | |
public $name = 'Something'; | |
} | |
class Magic | |
{ | |
private $values = ['name' => 'Something']; |
NewerOlder