Thursday 24 January 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...