----- Original Message ----- From: "Sabine" <[EMAIL PROTECTED]>
To: "PHP general" <php-general@lists.php.net>
Sent: Wednesday, September 07, 2005 7:14 PM
Subject: [PHP] Assign values in foreach-loop


Hello to all,

is it possible to assign values to the array for which I do the foreach-loop?

foreach ($_SESSION['arr1'] as $arr1) {
   foreach ($_SESSION['arr2'] as $arr2) {
       if ($arr1['id'] == $arr2['id']) {
           $arr1['selected'] = true;
       }
   }   }

I think $arr1 is only a temp-var, so the assignment won't reflect on $_SESSION['arr1'] . Is that right? Surely I can do it with a for-loop, but those arrays are a bit complex and a foreach would be much easier to read.

Thanks in advance for your answers
Sabine

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.18/91 - Release Date: 2005-09-06


Hi there!

Why not set $_SESSION['arr1'] = true ?

foreach ($_SESSION['arr1'] as $arr1) {
   foreach ($_SESSION['arr2'] as $arr2) {
       if ($arr1['id'] == $arr2['id']) {
           $_SESSION['arr1'] = true;
       }
   }   }

I think $arr1 is only a temp-var, so the assignment won't reflect on $_SESSION['arr1'] . Is that right?

I might add that is not always a good thing to use true or false with sessions. Use 1 and 0 instead. (or two diffrent numbers or anything else but true or false)

/G
http://www.varupiraten.se/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to