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