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
https://forums.phpfreaks.com/topic/161323-associative-arrays/
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
https://forums.phpfreaks.com/topic/161323-associative-arrays/#findComment-851416
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.