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
Subject: [PHP] Assign values i
In case it hasnt been said already, as long as your array has numeric and
consecutive keys, you could use 'for' instead of 'foreach'.
Jason
On 9/7/05, Gustav Wiberg <[EMAIL PROTECTED]> wrote:
>
>
> - Original Message -
> From: "Sabine" <[EMAIL PROTECTED]>
> To: "PHP general"
> Sent:
- 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-loop?
foreach ($_SESSION['arr1
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
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 $
8 matches
Mail list logo