Tema: poo array
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/09/2013, 19:33
Avatar de edgarisrael1992
edgarisrael1992
 
Fecha de Ingreso: junio-2013
Mensajes: 54
Antigüedad: 10 años, 10 meses
Puntos: 0
poo array

primero este es mi codigo y funciona correctamente. me forma numeros dentro de una tabla.


<?php
class llenar{

private $filas;
private $columnas;
private $arreglo=array();
private $altura;
private $anchura;
private $numero;

public function __construct($numero){
$this->filas=$numero;
$this->columnas=$numero;
$this->altura=$numero-1;
$this->anchura=0;
$this->numero=$numero*$numero;
}


function recorre(){

$numero=$this->numero;

if($numero==0){
echo '<table align="center" bgcolor="#999">';
for($i=0;$i<3;$i++){?>
<tr >
<?php for($j=0;$j<3;$j++){ ?>
<td>
<?php echo $this->arreglo[$i][$j]; ?>
</td>
<?php }?>
</tr>
<?php }?>
</table>
<?php
break;}

if($this->anchura>$this->columnas-1){
$this->anchura=0;}

if($this->altura==-1){
$this->altura=$this->columnas-1;}

if(empty($this->arreglo[$this->altura][$this->anchura])){

$this->arreglo[$this->altura--][$this->anchura++]=$numero;

}else{
++$this->altura;
if($this->altura>$this->filas-1){
$this->altura=0;
}
$this->arreglo[$this->altura--][$this->anchura++]=$numero;

}
--$this->numero;
$this->recorre();
}

}

?>

mi duda es la siguiente..
como puedo devolver el arreglo con un return

y otra es... como puedo asignar el valor del arreglo del return. en otro arreglo fuera de la clase y de ahy comenzar a imprimir en tabla.
masomenos tengo esta idea...
<?php
include("algoritmoFunciones.php");
$numero=3;
$arreglo=array();
$llen=new llenar($numero);
$arreglo=$llen->recorre();
?>

<table align="center" bgcolor="#999">
<?php for($i=0;$i<$numero;$i++){?> <!-- FILAS -->
<tr >
<?php for($j=0;$j<$numero;$j++){ ?><!-- COLUMNAS -->
<td>
<?php echo $arreglo[$i][$j]; ?>
</td>
<?php }?>
</tr>
<?php }?>
</table>