Avatar of Lennart Ericson
Lennart Ericson
Flag for Sweden asked on

How to delete values from an array using php

I have two arrays, $array_1 and $array_2.
If a value in $array_2 is also found in $array_1 it should be deleted from $array_1.
The same value might be found several times in both of the arrays. Is the value present in $array_2, regardless of number of appearances, it should be deleted from all appearances in $array_1.
Script language: php
What procedure do you recommend?

Avatar of undefined
Last Comment
Lennart Ericson

8/22/2022 - Mon
Peos John

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Julian Hansen

Only recommendation I would make over Peos John's reply is to rather use the www.php.net resource as a reference. W3 Schools is ok but PHP.Net is the definitive source and has a wealth of other related information in the examples, topic posts and related function lists

Ray Paseur

No points for this, please, but I would add that sometimes the most useful part of the online PHP manual are the user-contributed notes in the function reference.  Examples:
http://php.net/manual/en/function.array-diff.php#68623  <<< Especially this one!
Lennart Ericson

Sorry for late reply.
Thanks so much. It worked very well.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy