Thursday, January 24, 2019

php - How can i delete a item at index X in array?






Possible Duplicate:
How to delete an element from an array in php?






I have a list of things, cars for instance



$cars[0] = "audi";
$cars[1] = "saab";
$cars[2] = "volvo";

$cars[3] = "vw";


How do i delete "volvo" from the list?


Answer



$volvoIndex = array_search('volvo', $cars);
unset($cars[$volvoIndex]);

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...