Avatar of interclubs
interclubs
 asked on

Restructure Array in PHP

I have 2 arrays, one that looks like this:
$fieldsToInclude = array('name','phone','dob');

Then I have a second array the looks like this:
    [241] => Array(
            [name] => 'John Doe',
            [phone] => '98989712333',
            [dob] => '12/12/2001',
            [gender] => 'm',
            [address] => '170521 somewhere'
            ),
    [238] => Array
        (
            [name] => 'John Buck',
            [phone] => '11198989712333',
            [dob] => '12/1/2001',
            [gender] => 'm',
            [address] => '1233 somewhere'
        ),
    [239] => Array
        (
            [name] => 'John Smith',
            [phone] => '33398989712333',
            [dob] => '2/12/2001',
            [gender] => 'm',
            [address] => '43234 somewhere'
        )

I want to sort through this array, and create a new one, but only with the fields in $fieldsToInclude. So the array we would be identical, except with no gender or address.

Thanks!
PHP

Avatar of undefined
Last Comment
Beverley Portlock

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Beverley Portlock

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
or
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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes