Created
March 7, 2014 17:03
-
-
Save nathanrice/9415349 to your computer and use it in GitHub Desktop.
Example of unset not working properly
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 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