C
C
CrewCut2016-06-15 16:38:06
PHP
CrewCut, 2016-06-15 16:38:06

How to reset multidimensional array values ​​in php?

There is an array like this:

Array(
    [stock] => Array(
    [0] => 17-58-черный
    [1] => 17-54-черный
    [2] => 17-58-черный
  )

    [sold] => Array(
    [0] => 17-58-черный
    [1] => 17-54-черный
  )
)

The task is to go through each first level (stock_2014, sold, etc.) with a function array_count_valuesand replace its values ​​​​with the resulting ones, so that something like this comes out:
Array(
    [stock] => Array(
    [0] => Array
      ( 17-58-черный => 2 )
    [1] => Array
      ( 17-54-черный => 1 )
    )

    [sold] => Array(
    [0] => Array
      ( 17-58-черный => 1 )
    [1] => Array
      ( 17-54-черный => 1 )
    )
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SharuPoNemnogu, 2016-06-15
@CrewCut

uh, isn't it?

$arr = [
    'stock' => [
        0 => '17-58-черный',
        1 => '17-54-черный',
        2 => '17-58-черный',
    ],
    'sold' => [
        0 => '17-58-черный',
        1 => '17-54-черный',
  ]
];

$arr = array_map('array_count_values', $arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question