Alvaro
Alvaro

Reputation: 41605

Modify returned array CakePHP 2.2

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.

Upvotes: 0

Views: 152

Answers (2)

Mirko Pagliai
Mirko Pagliai

Reputation: 1240

nothing to do with cakephp, look for php cycles

Upvotes: 0

bfavaretto
bfavaretto

Reputation: 71939

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']);
}

Upvotes: 2

Related Questions