Skip to content

Instantly share code, notes, and snippets.

@piercemoore
Created April 3, 2012 15:29
Show Gist options
  • Select an option

  • Save piercemoore/2292935 to your computer and use it in GitHub Desktop.

Select an option

Save piercemoore/2292935 to your computer and use it in GitHub Desktop.
Simple Recursion Function within a Class
<?php
class Foo {
function __construct( $array ) {
$this->storage = $this->store($array);
}
function store( $array ) {
foreach( $array as $k => $v ) {
if( is_array( $v )) {
$output[$k] = $this->store( $v );
} else {
$output[$k] = $v;
}
}
return $output;
}
function show() {
print_r($this->storage);
}
}
$bar = array("One","Two","Three","Four");
$baz = array(
"One" => array(
"OneA",
"OneB" => array(
"OneAA",
"OneBB"
)
),
"Two" => array(
"TwoA"
)
);
print "<pre>";
$f = new Foo($bar);
$f->show();
$g = new Foo($baz);
$g->show();
print "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment