Online Forum To Support Coders With Technical Assistance - Read Write Execute

how to delete value from array in php

Ankit Agrawal
Ankit Agrawal
Published on July 15, 2015 · 1 min read

for this you have to find key of that value first then you can unset that key from array.

$yourArray = array(1,2,3,4,5,6,7,8,9);
$delateValue = 8;
$aKey = array_search($delateValue, $yourArray);
if (false !== $aKey) {
    unset($yourArray[$aKey]);
}
print_r($yourArray);
Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article How to get post image url in wordpress Next Article → How to get user details from id in wordpress