If you want to remove an array of elements from another array that have a particular value(s) here’s a neat way of doing it without any looping:
// our initial array
$arr_main = array('blue', 'green', 'red', 'yellow', 'green', 'orange', 'yellow', 'indigo', 'red');
// remove the elements who's values are yellow or red
$arr_to_rem = array('red', 'yellow');
echo ' '; print_r($arr_main); echo '
‘;
$arr_main = array_diff($arr_main, $arr_to_rem);
echo ‘
'; print_r($arr_main); echo '
‘;
$arr_main = array_values($arr_main);
echo ‘
'; print_r($arr_main); echo '
‘;
‘;
This is the output from the code above:
Array
(
[0] => blue
[1] => green
[2] => red
[3] => yellow
[4] => green
[5] => orange
[6] => yellow
[7] => indigo
[8] => red
)
Array
(
[0] => blue
[1] => green
[4] => green
[5] => orange
[7] => indigo
)
Array
(
[0] => blue
[1] => green
[2] => green
[3] => orange
[4] => indigo
)
Enjoy!
A great font/script for creating beautiful logos, posters, wedding invitations, blog posts, social media, and…
Realistic T-Shirt Mockup PSD which you can use freely to showcase your apparel design.
Classic coffee mug Mock-up Free PSD. Free mug mockup PSD to showcase your branding design…
Juliette - Stylish Handwritten Signature Font
XXII Aven Font Family - a new modern all-caps sans serif font with versatility in creativity.