ItSolutionStuff.com

PHP Remove Element from Array by Value Example

By Hardik Savani May 14, 2024
PHP

I will explain step by step tutorial php remove element from array by value. i would like to share with you how to remove array element by value in php. you will learn php remove item from array by value. you will learn php remove item from array based on value. Here, Creating a basic example of php remove element from array with specific value.

Here, i will give you very simple example of how to remove item by value in php.

Example 1:

index.php

<?php

function remove_element($array, $value) {

if(($key = array_search($value,$array)) !== false) {

unset($array[$key]);

}

}

$myArray = ["Apple", "Banana", "Mango"];

remove_element($myArray, 'Banana');

print_r($myArray);

?>

Output:

Array

(

[0] => Apple

[1] => Mango

)

i hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Remove First Element from Array in PHP?

Read Now →

How to Get First Element of Array in Javascript?

Read Now →

How to Remove Specific Value from Array in JQuery?

Read Now →

How to Remove Specific Element by Value from Array in PHP?

Read Now →

How to Get Maximum Key Value of Array in PHP?

Read Now →

How to Remove Empty Values from Array in PHP?

Read Now →

How to Add Prefix in Each Key of PHP Array?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →

How to Merge Two Array with Same Keys without Loop in PHP?

Read Now →