Thread: array()

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    11
    Rep Power
    0
    What will this statement do?

    $files = array ("file.txt");

    I'm confused about the difference between that statement and using the file() function.
    ex.

    $lines = file('file.txt');

    Thanks.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    $lines = file('file.txt');
    >>


    Your above line is correct.first one is wrong.if you want to create an array then only you need to do first one.

    $lines = file('file.txt');

    Here the above will take the contents from the file.txt and put it in $lines array.

    if you want to create an array then try something like..

    $lines = array('one','two','three','four');
    //create an array with above values...


    please go through the manual then you get very good understanding..



    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    11
    Rep Power
    0
    I understand what the second line will do, but I was curious as to what the first one will do. Will it throw everything from "file.txt" into an array? I saw it being used this way in a script, and I was wondering what they were accomplishing by using this method.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    array() defines a new array. So,

    $files=array("file.txt");

    is the same as:

    $files[0]="file.txt");

    It will not do anything with a file named file.txt, only assign that string to the variable.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    11
    Rep Power
    0
    So, the entire file is under one element of the array?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    No, array() has nothing to do with files, so:

    $files=array("file.text");

    just creates an array with a single element. That element contains the 9-character string "file.text". It does not know that this is the name of a file.

    [This message has been edited by scollo (edited September 19, 2000).]
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    11
    Rep Power
    0
    So, $files array contains a list of file names.

    Thanks everyone.

Similar Threads

  1. sort: find duplicate string elements in array
    By sciencelife in forum Java Help
    Replies: 3
    Last Post: January 27th, 2004, 01:29 PM
  2. C++ programming help.
    By Programming1 in forum C Programming
    Replies: 1
    Last Post: January 20th, 2004, 10:47 AM
  3. another remove array values from an array
    By robee in forum PHP Development
    Replies: 6
    Last Post: November 20th, 2003, 12:09 AM
  4. multi dimensional arrays - Can't grasp how to?
    By Kaleina in forum PHP Development
    Replies: 17
    Last Post: November 5th, 2003, 03:18 PM
  5. problem with array
    By Geekoidxp in forum PHP Development
    Replies: 3
    Last Post: October 12th, 2003, 01:22 PM

IMN logo majestic logo threadwatch logo seochat tools logo