D
D
d1KdaT2015-12-03 17:36:41
PHP
d1KdaT, 2015-12-03 17:36:41

How to extract a key from a subarray?

I have an array like:

$arr['data'][0]['ID']
$arr['data'][0]['static']
$arr['data'][1]['ID']
$arr['data'][1]['static']

etc.
How to make an array of the form:
$arr['data']['ID']['static'] from it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d1KdaT, 2015-12-04
@d1KdaT

On the advice of Vladislav Kopylov , I did through FOREACH:

foreach ($arr['data'] as $mm) {
  $copy_arr[$mm['tank_id']] = $mm['all']; // "all" = "static"
}

A
Artem Spiridonov, 2015-12-04
@customtema

$arr['data'] = $arr['data'][0]; only index 1 in the third line is confusing.
In general, it looks like a series of unsuccessful programming decisions. Most likely, something somewhere needs to be simplified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question