How to remove multiple elements from an array by value and re-index the array keys in PHP

1 Answer

0 votes
$arr = array("php", "java", "c", "c++", "c#", "python", "swift");
 
$arr = array_diff($arr, array("java", "c#"));
 
$arr = array_values($arr); // re-index

print_r($arr);
 
 
 
 
/*
run:
 
Array
(
    [0] => php
    [1] => c
    [2] => c++
    [3] => python
    [4] => swift
)

*/

 



answered Feb 17, 2021 by avibootz

Related questions

...