Information
This should be a fairly simple question. On my website I have a post_categorys in my database that has a structure like below
ID | Name
1 | Sports
2 | Health
3 | Movies
4 | Music
Now when I save a blog post I save the category_id such as 1 for movies in the blog_post table.
When printing out the blog post to my users I want to be able to get the blog post category name by something like $categorys[$blog_cat_id']['name']
Here is how I get all categorys for $categorys used above.
function getCategorysArray(){
$STH = $this->database->prepare('SELECT * FROM project_categorys');
$STH->execute();
return $STH->fetchAll();
}
But this returns the array in this format
Array
(
[0] => Array
(
[id] => 1
[0] => 1
[name] => Sports
[1] => Sports
)
[1] => Array
(
[id] => 2
[0] => 2
[name] => Health
[1] => Health
)
[2] => Array
(
[id] => 3
[0] => 3
[name] => Movies
[1] => Movies
)
[3] => Array
(
[id] => 4
[0] => 4
[name] => Music
[1] => Music
)
Therefor I am unable to use my desired method to get the category name ($categorys[$blog_cat_id']['name'])
Question
Is there a way I can remap the array somehow so that $array[1]['name'] = Sports would be the output?