S
S
Shameless192021-07-28 21:45:27
PHP
Shameless19, 2021-07-28 21:45:27

How to reformulate the code?

There is an array

$items = [
  [
  'name'=> "1name",
  'qual'=>34,
  ],

  ['name'=>'2name',
  'qual'=>2
  ],
];

Now, to get the second element of the array, I use Is it possible to do the same, but without using the name of the desired field ("qual")?
$My_qual= $item[$key]['qual'];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2021-07-29
@Shameless19

if you go strictly according to the task posed in the question, then you can take a list of object keys, take the one you need by number and use it, but you definitely don’t need to do this, no one guarantees that the order of the elements in the key array will remain the same, you will have to double-check everything.
$items[$key][array_keys($items[$key])[1]]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question