T
T
Troodi Larson2018-04-30 20:17:30
Laravel
Troodi Larson, 2018-04-30 20:17:30

How to correctly display an object under its id?

There is an object
$categories storing name and id, they can be accessed in foreach.
And how correctly to deduce name on id? That is, how to do something like this in OOP
$categories[0] - it will display the name and so on.
UP: for understanding, I have id 1 and 4
Can I pull out name by id?

$categories = DB::table('category')->get();
foreach($categories as $category){
  $sub[$category->id] = $category->name;
}

But it's kind of a crutch.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2018-04-30
@troodi

Here is a direct answer to a question on stackoverflow

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question