0

I was wondering if there's any simple way to modify and add a new index to a given array at CakePHP.

Currently I'm doing a loop like this:

$posts = $this->paginate('Post');

$a=0;
foreach($posts as $post){
    $posts[$a]['Read'] = myfunction($post['Post']['id']);
    $a++;
}

Thanks.

1
  • Could you be more specific how do you want the array to be modified? Commented Oct 27, 2012 at 11:53

2 Answers 2

2

You do have to loop, but you could use less code:

$posts = $this->paginate('Post');
foreach($posts as $a=>$post){
    $posts[$a]['Read'] = myfunction($post['Post']['id']);
}
Sign up to request clarification or add additional context in comments.

Comments

0

nothing to do with cakephp, look for php cycles

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.