Link to home
Start Free TrialLog in
Avatar of Colin Brazier
Colin BrazierFlag 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
User generated image
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
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Please try this -

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

Open in new window


or

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

Open in new window

Avatar of 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
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It does - thanks Julian.
You are welcome.
There might be a few more array questions coming up, I'm really struggling
Post away and then PM me
Will do, I think I've made some progress though.

Cheers