0

I work with Silex Framework and I would like to add $age to $result after the calculation of the age Is that possible??

$result = $app['db']->fetchAll($sql);

 foreach ($result as $DN) {
    $DT = $DN['dateN'];
        $am = explode('-', $DT);
        $an = explode('/', date('Y/m/d'));
        $age = $an[0] - $am[0];
        echo $age;
  }

 return $app['twig']->render('page.html',array('list' => $result,'age'=>$age));
1
  • $result['age'] = $age; ? Commented Apr 13, 2014 at 13:10

2 Answers 2

2

You can try to use a reference (with &) instead of a copy and add the item:

foreach ($result as &$DN) {
    $DT = $DN['dateN'];
    $am = explode('-', $DT);
    $an = explode('/', date('Y/m/d'));
    $age = $an[0] - $am[0];
    $DN['age'] = $age;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your fetchAll returns an array of arrays "referencing" your resultset

foreach($result as $index => $row) {
    // ....
    $result[$index] = $age;
}

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.