Probaly a simple one for you but I have the following array that contains all the categories from a database:
Array
(
[0] => Array
(
[id] => 1
[title] => Fitness News
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt tempor nunc, sit amet facilisis metus molestie nec. Nulla varius justo et felis euismod bibendum. Vestibulum suscipit tempus viverra. Mauris eros lorem, posuere eget mattis et, euismod id metus. In ac dignissim ligula. fdsfdsfdsfds fdsf fsd
[image1] => test
[image1_title] => test
[created] => 2012-03-26
)
[1] => Array
(
[id] => 2
[title] => Recommended Products
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt tempor nunc, sit amet facilisis metus molestie nec. Nulla varius justo et felis euismod bibendum. Vestibulum suscipit tempus viverra. Mauris eros lorem, posuere eget mattis et, euismod id metus. In ac dignissim ligula.gdsfdsfdsfdsfds
[image1] => H
[image1_title] => H
[created] => 2012-03-25
)
[2] => Array
(
[id] => 3
[title] => New Category
[description] => This is a new category
[image1] =>
[image1_title] =>
[created] => 2012-03-13
)
)
Now what I have is bassically a category ID, but from this I would like to get the category title from the above array.
Instead of searching the old array, I'd reformat the old array so it's much more usable:
$categories = array();
foreach( $old_categories as $item)
$categories[ $item['id'] ] = $item;
Now you can access anything to want based on ID. For example:
$id = 2;
echo $categories[ $id ]['title'];
echo $categories[ $id ]['description'];
$key = array_search ($category_id, $array);
echo $array [$key] ['title'];
or
$category_id = 1;
foreach ($array as $val) {
if ($val ['id'] == $category_id) {
$title = $val ['title'];
break;
}
}
echo $title
$key = array_search($categoryId, $array);
$title = $array[$key]['title'];