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
LVL 3
Colin BrazierAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
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 BrazierAuthor Commented:
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.
Julian HansenCommented:
This should do what you want
<?php
$x = array(
	array('comp_code' => 'KCL P', 'comp_desc' => 'Kent county league premier division'),
	array('comp_code' => 'IRC 1', 'comp_desc' => 'Bill Manklow Inter Regional Challenge Cup 1st round'),
	array('comp_code' => 'IRC 2', 'comp_desc' => 'Bill Manklow Inter Regional Challenge Cup 2nd round')
);

$n = array();

foreach($x as $i) {
	$n[$i['comp_code']] = $i['comp_desc'];
}
echo "<pre>" . print_r($n, true) . "</pre>";

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Colin BrazierAuthor Commented:
It does - thanks Julian.
Julian HansenCommented:
You are welcome.
Colin BrazierAuthor Commented:
There might be a few more array questions coming up, I'm really struggling
Julian HansenCommented:
Post away and then PM me
Colin BrazierAuthor Commented:
Will do, I think I've made some progress though.

Cheers
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.