Answer the question
In order to leave comments, you need to log in
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;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question