Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created November 9, 2016 09:47
Show Gist options
  • Save gorkamu/430cc2f1f23246dd146a707dd92628e5 to your computer and use it in GitHub Desktop.
Save gorkamu/430cc2f1f23246dd146a707dd92628e5 to your computer and use it in GitHub Desktop.
Ejemplo de iteración sobre un objeto
<?php
class Gorkamu
{
public $nombre = 'Gorkamu';
public $web = 'http://www.gorkamu.com';
protected $edad = '27';
private $telefono = '66. ... ...';
public function iterar() {
foreach ($this as $clave => $valor) {
print "$clave => $valor\n";
}
}
}
$gorkamu = new Gorkamu();
foreach($gorkamu as $clave => $valor) {
print "$clave => $valor\n";
}
echo PHP_EOL;
$gorkamu->iterar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment