CyberShot Posted January 11, 2009 Share Posted January 11, 2009 I am working on learning php. I want to work with wordpress more. I have seen two symbols. Not sure what they are called. maybe you can tell me. One looks like this -> the other looks like this => case in point. Here is a line from wordpress to get the post <?php $recent = new WP_Query("cat=12&showposts=0"); while($recent->have_posts()) : $recent->the_post();?> so is the line above saying that $recent is equal to having a post? what does the -> mean in the line above? if you could be as detailed as possible with an explanation, it would be greatly appreciated. thanks. Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 11, 2009 Share Posted January 11, 2009 -> is used to indicate, that have_posts() and the_post() are methods of $recent object. This is related to object oriented programming, and if you want to learn more about it start here http://www.php.net/manual/en/language.oop5.php => on the other hand is used in two cases (as far as I remember) 1. To define items of array $arrayVariable = array( "foo" => "text", "bar" => 123, ); 2. In foreach loops foreach ($arrayVariable AS $key => $value) { echo "$key: $value <br/>\n"; } if you use $arrayVariable from point 1 above, it will display foo: text bar: 123 Quote Link to comment Share on other sites More sharing options...
CyberShot Posted January 11, 2009 Author Share Posted January 11, 2009 ok, why don't the posts need to be echoed out to the browser? i would think you would need to do this <?php echo the_post(); ?> Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 11, 2009 Share Posted January 11, 2009 It is being done within the method Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 11, 2009 Share Posted January 11, 2009 It is likely that the_post() method does just that. It's echoing posts. Take a look at this example class exampleClass { public function displayArray() { foreach($this->array AS $key => $value) echo "$key: $value <br/>\n"; } private $array = array ( "foo" => "text", "bar" => 123, ); } $object = new exampleClass; $object->displayArray(); Code not tested [edit] typo Quote Link to comment Share on other sites More sharing options...
CyberShot Posted January 11, 2009 Author Share Posted January 11, 2009 ok. thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.