Avatar of Colin Brazier
Colin Brazier
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Remove level of an array

Hi experts,

I need to change an array from this
array to alter
to this:

Array
(
     [KCL P] => Kent county League Premier division
     [IRC 1] => Bill Manklow Inter Regional Challenge Cup 1st round
     [IRC 2] => Bill Manklow Inter Regional Challenge Cup 2nd round
)

Any help appreciated.

Col
PHP

Avatar of undefined
Last Comment
Colin Brazier

8/22/2022 - Mon
Pawan Kumar

Please try this -

$1DimensionalArray = array_map('current', $2Dimensionalarray);

Open in new window


or

 $1DimensionalArray  = array_reduce($2Dimensionalarray, 'array_merge', array())

Open in new window

Colin Brazier

ASKER
After I removed the initial numbers from the array names,
$1DimensionalArray = array_map('current', $2Dimensionalarray);
gives
Array
(
    [0] => KCL P
    [1] => IRC 1
    [2] => IRC 2
)

$1DimensionalArray  = array_reduce($2Dimensionalarray, 'array_merge', array())
gives
Array
(
    [comp_code] => Other
    [comp_desc] => Other
)

Other is the last option in each case.
ASKER CERTIFIED SOLUTION
Julian Hansen

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
Colin Brazier

ASKER
It does - thanks Julian.
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
Julian Hansen

You are welcome.
Colin Brazier

ASKER
There might be a few more array questions coming up, I'm really struggling
Julian Hansen

Post away and then PM me
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Colin Brazier

ASKER
Will do, I think I've made some progress though.

Cheers