Jump to content

[SOLVED] array modified without modifing instruction Oo


Zwiter

Recommended Posts

Hello all

More than explanation, here is the code :

<?php
print_r($columns);
print_r($titles);
foreach($columns as $key => $value) {
print_r($titles);
die;
[other instructions]
}?>

And here is extract of each print_r:

print_r($columns):
Array
(
  [project_cmts] => Array
    (
      [title] => Project comments
      [excel] => Project comments
    )
    [...]
)

first print_r($titles):
Array
(
    [...]
    [Comments] => //empty string
    [...]
)

fsecond print_r($titles):
Array
(
    [...]
    [Comments] => Array
        (
            [title] => Project comments
            [excel] => Project comments
        )
    [...]
)

 

As you can see, the content of $titles was changed, but how?

 

Thank you!

Z.

Link to comment
Share on other sites

i have a die instruction.

how come the next instructions may help?

Anyway, here they are :

<?php
print_r($columns);
print_r($titles);
foreach($columns as $key => $value) {
print_r($titles);
die;

if (array_key_exists($value['excel'], $titles))
	$titles[$value['excel']] = $key;
else $titles[$value['excel']] = false;
}
?>

 

But the problem is still the same with this code:

<?php
print_r($columns);
print_r($titles);
foreach($columns as $key => $value) {
print_r($titles);
die;
}

?>

Link to comment
Share on other sites

I have found the problem.

I found that the only way left after i have delete all instuctions inside my foreach is reference.

So i trac all the reference in my page ( I use some to modify data, especialy array content).

 

And i found it :

//  ok
$titles = array_flip($titles);
foreach ($titles as $key => $value)
	$titles[$key] = NULL;

//  no ok
$titles = array_flip($titles);
foreach ($titles as &$value)
	$value = NULL;

 

I am programming in perl and php at same time. (php for the user interface, and perl to run scripts on data (DNA stuff))

So variables which are local in perl, and disapear after the end of the block code are not deleted in php. So the reference stayed and annoyed me.

 

thank you for your help.

Z.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.