Avatar ·

Removing an element from a PHP array by value, not by key

Hello everyone! I'm just starting to learn PHP and ran into a problem. I have an array with user names, and I need to remove a specific name from it, but I don't know which index (key) it's at.\n\nHere's an example of my code:\n\n```php\n$users = ['Ivan', 'Maria', 'Petr', 'Anna', 'Ivan'];\n// I need to remove 'Petr' from this array\n```\n\nI know that to remove by key you use `unset($array[$key])`, but what if I only know the value? I tried writing a loop that iterates through the array and compares values, but it looks too cumbersome, especially if the array is large.\n\nIs there a built-in function in PHP that allows you to remove an element by its value? And what should I do if there are multiple identical values in the array, for example, the name 'Ivan' appears twice — do I need