Jump to content

Associative arrays


simpli

Recommended Posts

Hi,

I have some records that I return through a function as a rowset. I want to go through each row and echo it. I used zend's toarray function to turn the rowset into an set of arrays that I loop through. It was my understanding that this

    <td><?php echo $treePathRow->ancestor_id;?></td> 

 

would allow me to access the column ancestor_id of an row ( or in this case the array corresponding to it).

 

In fact this it is that notation that works

 <td><?php echo $this->escape($treePathRow["ancestor_id"]);?></td> 

 

Isn't the '->' a valid way to get access to the data of an associative array?

 

Thanks for clarifying.

JR

 

Link to comment
Share on other sites

-> is to go inward into an object

<?php
class Frog {
  public $name:
  public function Frog($name) {
    $this->name = $name;
  }
  public function talk() {
    echo $this->name.' Says: Ribbit<br />';
  }
}
$rudie = new Frog('Rudie');
$rudie->talk();
?>

$rudie is an instance of the Frog class...

-> tells it to go inside $rudie(Frog)

and use the function talk() which would echo Rudie Says: Ribbit<br />

 

 

to reference a element inside an associative array you use the same brackets you use on a numbered array

 

$arrayVar['nameOfElement']

 

and for numbered it would be: $arrayVar[10] for the 11th Element

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.