1

I pass an array to a view, which has code like this:

<?php foreach ($this->results as $r): ?>
<div>
<?php echo $this->url(array('id' => $this->escape($r[RecordID]) ....

Suppose I want to use object notation:

<?php foreach ($this->results as $r): ?>
<div>
<?php echo $this->url(array('id' => $this->escape($r->RecordID) ....

Is this possible?

2
  • If $r is object, then it is possible. If it is an array, than it is not. Commented Jun 17, 2013 at 4:10
  • 1
    I think the important question is, why is it an array to begin with? By casting it you may be curing the symptoms but hiding the issue rather than solving it. Commented Jun 17, 2013 at 7:18

2 Answers 2

1

Your only real option is to cast the array to an object prior to using it this way.

  <?php foreach ($this->results as $r): ?>
  <div>

  <?php $r = (object)$r;
        echo $this->url(array('id' => $this->escape($r->RecordID) ....
Sign up to request clarification or add additional context in comments.

Comments

1

Yes you can try with Object to use object array in view like

 <?php foreach ($this->arrUserList as $data) { ?>
                 <?php $data = (object)$data; ?>

  <td><?php echo $this->escape($data->userName); ?></td>

Let me know if i can help you more.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.