Last active
July 10, 2019 18:49
-
-
Save BEcraft/89fd9fe499151c19ee521a7fcb024005 to your computer and use it in GitHub Desktop.
Posiciones
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 A | |
{ | |
/** | |
* @var string | |
*/ | |
private $valor_1 = ""; | |
/** | |
* @var string | |
*/ | |
private $valor_2 = ""; | |
/** | |
* @var string | |
*/ | |
private $valor_3 = ""; | |
/** | |
* @var array | |
*/ | |
private $lista = []; | |
private const TOTAL = 3; | |
public function __construct() | |
{ | |
for ($i = 0; $i < 10; ++$i) | |
{ | |
$this->lista[("BEcraft=" . $i)] = mt_rand(1, 100); | |
} | |
} | |
public function calcular(): array | |
{ | |
$valores = $this->lista; | |
$contador = 0; | |
arsort($valores); | |
while ($contador++ < self::TOTAL) | |
{ | |
$cabezera = "valor_{$contador}"; | |
if ($this->{$cabezera} === null) | |
{ | |
break; | |
} | |
$this->{$cabezera} = key($valores) . ":" . array_shift($valores); | |
} | |
return $valores; | |
} | |
public function mostrar(): array | |
{ | |
return [$this->valor_1, $this->valor_2, $this->valor_3]; | |
} | |
} | |
$a = new A(); | |
var_dump($a->mostrar(), $a->calcular(), $a->mostrar()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment