Skip to content

Instantly share code, notes, and snippets.

@nathanrice
Created March 7, 2014 17:03
Show Gist options
  • Save nathanrice/9415349 to your computer and use it in GitHub Desktop.
Save nathanrice/9415349 to your computer and use it in GitHub Desktop.
Example of unset not working properly
<?php
class Fruit_List {
private $fruit = array();
function __construct() {
$this->add_fruit( array(
1 => 'apple',
2 => 'orange',
3 => 'bananna',
4 => 'pear',
) );
$this->fruit_list();
}
function add_fruit( $fruit = array() ) {
$this->fruit = array_merge( $this->fruit, $fruit );
}
function fruit_list() {
//* Delete 'pear'
unset( $this->fruit[4] );
echo '<ul>';
foreach ( $this->fruit as $fruit ) {
echo '<li>' . $fruit . '</li>';
}
echo '</ul>';
}
}
new Fruit_List;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment