How to remove specific element from an array in PHP

1 Answer

0 votes
$arr = array("php", "java", "c", "c#", "c++", "javascript", "python");

if (($key = array_search("javascript", $arr)) !== false) {
    unset($arr[$key]);
}
 
print_r($arr);
 
 
 
 
 
/*
run:
 
Array
(
    [0] => php
    [1] => java
    [2] => c
    [3] => c#
    [4] => c++
    [6] => python
)
 
*/

 



answered Jun 16, 2021 by avibootz

Related questions

1 answer 173 views
2 answers 142 views
3 answers 195 views
2 answers 158 views
2 answers 251 views
...