How do I return the cat_name value instead of array with PHP? -


i did digging , understand array means there multiple values coming query. post found print_r see values. how return 1 of values though?

this:

<?php       $category = get_the_category();     $parent = get_cat_name($category[0]->category_parent);     $cat_name = get_the_category($category[cat_name]);     echo 'category' . $category . '<br />';     echo 'parent: ' . $parent . '<br />';     echo 'cat name: ' . $cat_name . '<br />';      print_r ($cat_name);      ?> 

returns this:

categoryarray parent: location cat name: array array (   [0] => stdclass object (     [term_id] => 11     [name] => nashville     [slug] => nashville     [term_group] => 0     [term_taxonomy_id] => 11     [taxonomy] => category     [description] =>     [parent] => 8     [count] => 1     [object_id] => 20     [cat_id] => 11     [category_count] => 1     [category_description] =>     [cat_name] => nashville     [category_nicename] => nashville     [category_parent] => 8   ) ) 

how make $cat_name return nashville? cat_name = nashville according print_r function. wordpress site if makes difference, guessing simple coding question.

you're dealing object there, first element in array.

note says array ( [0] => stdclass object (

use square brace syntax access array members

$array_name['key_name'] 

and arrow objects properties

$object->property_name 

so in case,

$category[0]->cat_name 

is 'nashville'.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -