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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

0
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.
0
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

1

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
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

Cheers
0
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.