Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread Sabine
Thanks, Gustav for your answer. I already solved my problem (see below) with help of other members of the list. Gustav Wiberg schrieb: - Original Message - From: "Sabine" <[EMAIL PROTECTED]> To: "PHP general" Sent: Wednesday, September 07, 2005 7:14 PM Su

Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread Jason Davidson
<[EMAIL PROTECTED]> > To: "PHP general" > 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

Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread Gustav Wiberg
- Original Message - From: "Sabine" <[EMAIL PROTECTED]> To: "PHP general" 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-

Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread Edward Vermillion
Jordan Miller wrote: Hello, You simply need the $key variable, then you can set a new value for $arr[$key] for each array element: $value) { $arr[$key] = $value * 2; } // $arr is now array(2, 4, 6, 8) ?> http://www.php.net/foreach If you have PHP 5, you can perhaps more efficiently do t

[PHP] Assign values in foreach-loop: Problem solved

2005-09-07 Thread Sabine
Thanks a lot for your fast answers, I'll do it like -TG and Jordan in his last post suggested! Sabine Original-Nachricht Betreff: [PHP] Assign values in foreach-loop Datum: Wed, 07 Sep 2005 19:14:40 +0200 Von:Sabine <[EMAIL PROTECTED]> Antwort an:

Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread Jordan Miller
sorry, i didn't fully answer the questions... if i understand your multidimensional array correctly, your code should be something like: foreach ($_SESSION['arr1'] as $key => $arr1) { foreach ($_SESSION['arr2'] as $arr2) { if ($arr1['id'] == $arr2['id']) { $_SESSION['arr1

Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread tg-php
Yeah, you can assign values, but you have to keep track of keys, so you'll want to use the => operator for foreach (pardon my reformatted, I feel naked without my braces): foreach ($_SESSION['arr1'] as $key1 => $arr1) { foreach ($_SESSION['arr2'] as $key2 => $arr2) { if ($arr1['id']

Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread Jordan Miller
Hello, You simply need the $key variable, then you can set a new value for $arr[$key] for each array element: $value) { $arr[$key] = $value * 2; } // $arr is now array(2, 4, 6, 8) ?> http://www.php.net/foreach If you have PHP 5, you can perhaps more efficiently do this: As of PHP 5, yo

Re: [PHP] Assign values in foreach-loop

2005-09-07 Thread Edward Vermillion
Sabine wrote: 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 $

[PHP] Assign values in foreach-loop

2005-09-07 Thread Sabine
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