ID:               16269
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Feedback
 Bug Type:         Arrays related
 Operating System: windows 2000
 PHP Version:      4.1.2
 New Comment:

That 1 is not what I meant, I was talking about => instead of =.
You are using 
foreach ($array1 as $key = $val) {
and it should be
foreach ($array1 as $key => $val) {

Does it work now?


Previous Comments:
------------------------------------------------------------------------

[2002-03-26 08:33:30] [EMAIL PROTECTED]

No, that wasn't the reason. I only misspelled the foreach-loop 
when I wrote the bug report (forgot the '1').
Sascha

------------------------------------------------------------------------

[2002-03-26 08:04:48] [EMAIL PROTECTED]

Your foreach-loop is wrong. It should be 
foreach ($array1 as $key => $val) {

Does it work now?

------------------------------------------------------------------------

[2002-03-25 15:36:33] [EMAIL PROTECTED]

foreach ($array1 as $key = $val) {
    if ($val["a"] == $val["b"]) {
        $array2[] = array_splice($array1,$key,1);
    }
}

is the correct code. I forgot the '1' in the first variable

------------------------------------------------------------------------

[2002-03-25 15:34:16] [EMAIL PROTECTED]

Hi folks,

I'm using PHP 4.1.2 as module with apache 1.3.23

I have this array:

$array1[0] = array("a" => 3, "b" => 3);
$array1[1] = array("a" => 9, "b" => 3);
$array1[2] = array("a" => 11, "b" => 11);
$array1[3] = array("a" => 11, "b" => 11);
$array1[4] = array("a" => 15, "b" => 11);
$array1[5] = array("a" => 2, "b" => 2);

I want to split the array in to arrays with array1 containing all
elements where a = b and array2 a <> b

The correct result should be
even: element 0,2,3,5
uneven: element 1,4

I used the following code to split the array:

foreach ($array as $key = $val) {
    if ($val["a"] == $val["b"]) {
        $array2[] = array_splice($array1,$key,1);
    }
}

$array1 should now contain all uneven elements and $array2 all even
elements (with a different structur but that doesn't matters here).

But the result is:
$array1 contains element 1,3,4
$array2 contains 4 elements but one is empty! The data of element 3 are
missing.

When I run the script with this comparison:
if ($val["a"] != $val["b"])

I got the correct numbers of elements in each array (2 and 4)
but with wrong values.

I think this is a bug. Please inform me if you have investigated the
issue and found a explanation (maybe I did something wrong).

best,
Sascha

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=16269&edit=1

Reply via email to