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
<[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
- 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-
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
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:
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
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']
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
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 $
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
10 matches
Mail list logo