N
N
Nikolay2018-07-10 16:50:36
PHP
Nikolay, 2018-07-10 16:50:36

How to correctly implement a selection by ID if it does not match the key?

Hello!
In general, we have a database with, say, goods, something like this:

id | name | ...
1  | some name | ...
3  | another name | ...
17 | more name | ...

Making a request, we get it as an array:
$arr = [
  [0] => [
    'id' => 1,
    'name' => 'some name',
    ...
  ],
  [1] => [
    'id' => 3,
    'name' => 'another name',
    ...
  ],
  [2] => [
    'id' => 17,
    'name' => 'more name',
    ...
  ],
]
(The array keys do not match the product ID)
How do you get the data, for example, when you need to use the $arr[searcheableID]['name']?
Where searcheableID is the ID you need :)
I usually override the keys foreach :) But something tells me that this is not very correct. Can you tell me what method you use?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2018-07-10
@rim89

what prevents at the level of the request to the database to get an array with searcheableID ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question