Answers for "remove value in array php"

PHP
17

php delete element by value

$colors = array("blue","green","red");

//delete element in array by value "green"
if (($key = array_search("green", $colors)) !== false) {
    unset($colors[$key]);
}
Posted by: Guest on October-30-2019
13

php remove item array

$items = ['banana', 'apple'];

unset($items[0]);

var_dump($items); // ['apple']
Posted by: Guest on March-20-2020
6

Deleting an element from an array in PHP

$array = [0 => "a", 1 => "b", 2 => "c"];
unset($array[1]); //Key which you want to delete
/*
$array:
[
    [0] => a
    [2] => c
]
*/
//OR
$array = [0 => "a", 1 => "b", 2 => "c"];
array_splice($array, 1, 1);//Offset which you want to delet
/*
$array:
[
    [0] => a
    [1] => c
]
*/
Posted by: Guest on May-18-2020
0

php array remove value if exists

<?php
$myArray = array ('Alan', 'Peter', 'Linus', 'Larry');
$pos = array_search('Linus', $myArray);
echo 'Linus found at: '.$pos;
// Remove from array
unset($myArray[$pos]);
print_r($myArray);
?>
Posted by: Guest on April-07-2021
0

php remove element from array by value

// matrix array
foreach($appsList as $key => $app) {
            if($app["app_status"] !== "approved") {
                // remove orange apps
                unset($appsList[$key]);
            }
}
Posted by: Guest on January-15-2021
0

remove array values php

array_splice(array, start, length, array)
Posted by: Guest on November-03-2020

Code answers related to "remove value in array php"

Browse Popular Code Answers by Language