Forum Moderators: coopster

Message Too Old, No Replies

simple code to change elements of array

changing a specified value, or line in .txt

         

NL_Cartman

11:01 am on Oct 7, 2003 (gmt 0)

10+ Year Member



Hi,

I have some code that rewrites a data.txt file, in order to change just two values in one of the 10 lines.

I've played with array_splice , but that doesnt seem to do it;
i would like someting like this :
if ($x = $data[0]) { $data[4]=10 ; $data[5]=20 }

*leaving $data[6],7,8 un-touched

i think it shouldnt be to tough?, but again i cant get it right! :S

ergophobe

4:11 pm on Oct 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't really understand. Where do the values of $x and those in the $data array come from?

Also can you post 2-3 lines from the data file (but please, not the whole thing or your whole script)?

Tom

NL_Cartman

8:44 pm on Oct 8, 2003 (gmt 0)

10+ Year Member



hi, i think i can get it right, i'll be back

thnx!

jetboy_70

10:11 am on Oct 9, 2003 (gmt 0)

10+ Year Member



Typos again. Try:

if ($x == $data[0]) { $data[4]=10; $data[5]=20; }

I don't see why that wouldn't work, although admittedly I haven't tested it.

ergophobe

2:47 pm on Oct 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh right, same problem as in NL_Cartman's post on if/elseif/else problems.

NL - Look there for an explanation of how confusing the assignment and comparison operator will mess you up.