nimzie Posted December 9, 2007 Share Posted December 9, 2007 I make a call to print_r ($row); in my application. I want to access the item_title and ask if ( $row->item_title == 1 ) { Do whatever } I don't seem to have the syntax correct or understand how I would address each level of the array. Any help would be appreciated. Thanks Adam stdClass Object ( [id] => 25 [title] => Lorem Ipsum Products [title_alias] => Lorem Ipsum Products [introtext] => <p>Proin justo tellus, elementum sit amet, aliquam ut, convallis nec, lectus. Integer quam justo, nonummy eget, eleifend ut, facilisis vel, est. Curabitur eget leo non tellus ullamcorper pharetra. </p> [fulltext] => [state] => 1 [sectionid] => 9 [mask] => 0 [catid] => 24 [created] => 2007-12-06 12:35:40 [created_by] => 62 [created_by_alias] => [modified] => 2007-12-06 22:23:43 [modified_by] => 62 [checked_out] => 0 [checked_out_time] => 0000-00-00 00:00:00 [publish_up] => 2007-12-06 12:34:34 [publish_down] => 0000-00-00 00:00:00 [images] => [urls] => [attribs] => pageclass_sfx= back_button= item_title=1 link_titles= introtext=1 section=0 section_link=0 category=0 category_link=0 rating= author= createdate= modifydate= pdf= print= email= keyref= docbook_type= [version] => 2 [parentid] => 0 [ordering] => 1 [metakey] => [metadesc] => [access] => 0 [hits] => 0 [author] => Administrator [usertype] => Super Administrator [category] => Private Banking [section] => Products [groups] => Public [sec_pub] => 1 [cat_pub] => 1 [sec_access] => 0 [cat_access] => 0 [sec_id] => 9 [cat_id] => 24 [prev] => [next] => [text] => <p>Proin justo tellus, elementum sit amet, aliquam ut, convallis nec, lectus. Integer quam justo, nonummy eget, eleifend ut, facilisis vel, est. Curabitur eget leo non tellus ullamcorper pharetra. </p> ) Link to comment https://forums.phpfreaks.com/topic/80875-talking-to-arrays-print_r/ Share on other sites More sharing options...
dsaba Posted December 9, 2007 Share Posted December 9, 2007 use a foreach loop, running this code might help you understand how it works <?php //the object name is $myObject foreach ($myObject as $key => $val) { //goes through the whole object // you can access each key or title with $key //you can access each value or item with $val echo "$key => $val<br>\r\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/80875-talking-to-arrays-print_r/#findComment-410509 Share on other sites More sharing options...
nimzie Posted December 10, 2007 Author Share Posted December 10, 2007 I just want to check the setting for item_title in $row which is the object I am outputting in that print_r. I want to check and see if it's set to 1 and if so, do whatever. I'm more wondering the syntax of what I shoudl be doing cause nothing seems to be working... Thanks Link to comment https://forums.phpfreaks.com/topic/80875-talking-to-arrays-print_r/#findComment-410638 Share on other sites More sharing options...
kratsg Posted December 10, 2007 Share Posted December 10, 2007 If this is a simple array, you CAN do this: $value = $some_array["title"]; //do whatever you want with $value... If you're looking for a more generalized function for an object that you convert to an array, w/e... I'm sure something like this helps: function get_value($array,$key){ foreach($array as $index=>$value){ if($index == $key){return $value;} } return false; } Simple function that can get other types of keys for you... So, taking your array for instance (let's call it $some_array) $value = get_value($some_array,"title"); //do whatever you want with $value... Link to comment https://forums.phpfreaks.com/topic/80875-talking-to-arrays-print_r/#findComment-410644 Share on other sites More sharing options...
nimzie Posted December 10, 2007 Author Share Posted December 10, 2007 Hmm, upon further investigation, this is an object. It is a joomla core object called mosParameters. I'm still figuring out how to address the individual members of the object. I'll get er. Any suggestions appreciated. Cheers! Adam Link to comment https://forums.phpfreaks.com/topic/80875-talking-to-arrays-print_r/#findComment-410922 Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 It is a joomla core object called mosParameters. I'm still figuring out how to address the individual members of the object. $obj->member; Link to comment https://forums.phpfreaks.com/topic/80875-talking-to-arrays-print_r/#findComment-410923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.