Jump to content

explain these please


CyberShot

Recommended Posts

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.

Link to comment
Share on other sites

-> 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

Link to comment
Share on other sites

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 :P

 

[edit]

typo

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.