How to delete an array element based on key in PHP?
Hi Dev,
In this article, we will discuss how to delete an array element based on key in PHP. We can get the delete array elements by using array_unique() function. This function will remove the duplicate values from the array.
There are example to check if remove duplicate values from array in php. in this example, we will use to unset() function to check if How to delete an array element based on key in PHP . so let's the following example with output.
Example 1:
index.php
<?php
// Declare arr variable
// and initialize it
$arr = array('G', 'E', 'E', 'K', 'S');
// Display the array element
print_r($arr);
// Use unset() function delete
// elements
unset($arr[2]);
// Display the array element
print_r($arr);
?>
Output:
Array
(
[0] => G
[1] => E
[2] => E
[3] => K
[4] => S
)
Array
(
[0] => G
[1] => E
[3] => K
[4] => S
)
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example