Jump to content

Add new line to array...


EagerWolf

Recommended Posts

I have got file which includes array... I would like to add new things to array...

 

I have got form ... user must enter key and value ...

 

Than I have got a code..

 

function add($var1, $var2)

{

include('tmp.php');

$filename = 'test.php';

$fh = fopen($myFile, 'w');

 

 

 

 

if(array_key_exists($var1, $myarray))

{

print "Napaka, v arrayu je ze zapis z enakim kljucem";

}

 

else

{

        $temp_var = array

        (

        $var1 => $var2,

        );

$temp_array = array_merge($slovenski, $temp_var);

if (is_writable($filename))

{

echo "TRUE";

}

foreach ($temp_array as $key => $value)

{

$stringData = $key;

fwrite($fh, $stringData);

        }

fclose($fh);

}

}

 

I get warning:

Warning: fwrite(): supplied argument is not a valid stream resource in ...

 

I set test.php to 777... Also check if file is writable returns true. I've tried to print_r my new array and it is working just great...

 

So there must be a problem with fwrite!

 

Can u help me...

 

Best regards,

Matija

Link to comment
https://forums.phpfreaks.com/topic/36854-add-new-line-to-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.