php array remove value if exists

Solutions on MaxInterview for php array remove value if exists by the best coders in the world

showing results for - "php array remove value if exists"
Lorenzo
08 Jul 2020
1<?php
2$myArray = array ('Alan', 'Peter', 'Linus', 'Larry');
3$pos = array_search('Linus', $myArray);
4echo 'Linus found at: '.$pos;
5// Remove from array
6unset($myArray[$pos]);
7print_r($myArray);
8?>