0
0
0ldn0mad2019-08-02 19:31:46
PHP
0ldn0mad, 2019-08-02 19:31:46

How to display the value of an array by index and field name?

Help solve the problem, please.
Problem condition:
An array is given:

$arrEmployees = [
      1 => [
        'name' => 'user1',
        'surname' => 'surname1',
        'salary' => 1000,
      ],
      2 => [
        'name' => 'user2',
        'surname' => 'surname2',
        'salary' => 2000,
      ],
      3 => [
        'name' => 'user3',
        'surname' => 'surname3',
        'salary' => 3000,
      ],
      4 => [
        'name' => 'user4',
        'surname' => 'surname4',
        'salary' => 4000,
      ],
      5 => [
        'name' => 'user5',
        'surname' => 'surname5',
        'salary' => 5000,
      ],
    ];

It is necessary to build a function with two parameters - $num (user number by key - from 1 to 5) and $str (one of the names of the array fields - name, surname or salary. The function should display the value of the array field based on the two input parameters.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2019-08-02
@0ldn0mad

and what's the problem? https://ideone.com/Un1FZO
I'll leave the beautification and error checking to you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question