M
M
Max Ba2020-05-29 15:06:52
PHP
Max Ba, 2020-05-29 15:06:52

How to fill an array with a property of another?

Task. Fill array $b with numbers 1, 2, 3, 4 only.

$a = [
  [1, 1000],
  [2, 1500],
  [3, 2000],
  [4, 2500],
];

$b = [];
foreach($a as $v){
  $b[] = $v[0];
}

Is there a function, in one line, that can do this? No cycle like mine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-29
@phpcoder81

array_column

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question