-2

I am trying to get values for each field eg. translation in subarrays without foreach. Is it possible?

Array
(
    [0] => Array
        (
            [group_id] => 11
            [group_translation] => Extras
            [id] => 21
            [operation] => +
            [price] => 5
            [price_by] => once
            [price_type] => fixed
            [translation] => Pick up
            [price_total] => 5
        )

    [1] => Array
        (
            [group_id] => 11
            [group_translation] => Extras
            [id] => 22
            [operation] => +
            [price] => 10
            [price_by] => once
            [price_type] => fixed
            [translation] => Drinks
            [price_total] => 10
        )

)

Thank you!

ucMedia
  • 4,105
  • 4
  • 38
  • 46
Rafal
  • 145
  • 1
  • 2
  • 8
  • http://stackoverflow.com/q/1494953 – Rizier123 Jan 03 '17 at 18:15
  • 1
    Welcome to SO. Please have a look at [tour]. You may also want to check [What topics can I ask about](http://stackoverflow.com/help/on-topic), and [ask], and how to create a [mcve]. Post the code you have tried and the errors you have received. Be as specific as possible as it will lead to better answers. – happymacarts Jan 03 '17 at 18:15

1 Answers1

0

Sure that is possible:

<?php
$data = [
    [
        'group_id' => 11,
        'group_translation' => 'Extras',
        'id' => 21,
        'operation' => '+',
        'price' => 5,
        'price_by' => 'once',
        'price_type' => 'fixed',
        'translation' => 'Pick up',
        'price_total]' => 5
    ],
    [
        'group_id' => 11,
        'group_translation' => 'Extras',
        'id' => 22,
        'operation' => '+',
        'price' => 10,
        'price_by' => 'once',
        'price_type' => 'fixed',
        'translation' => 'Drinks',
        'price_total' => 10
    ]
];

$extract = [];
array_walk($data, function($element) use (&$extract) {
    $extract[] = $element['translation'];
});
var_dump($extract);

The output obviously is:

array(2) {
  [0] =>
  string(7) "Pick up"
  [1] =>
  string(6) "Drinks"
}
arkascha
  • 41,620
  • 7
  • 58
  • 90