How can I take a list and make each row a value in an array?
If you have a text file that looks like this :
Each line can magically be an element in the array using the PHP file()
function, like so :
$lines = file('info.txt');
print $lines; // john|orange|cow
print $lines; // sam|green|goat
print $lines; // mick|red|dragon
Using explode() will help seperate the lines by the seperator, which in
this case is a '|' , the following will loop through the text file,
explode each line and print out the given parts. We're assuming that
the text file (info.txt) has this format :
In the above, we could replace:
$p = explode('|', $line);
list($name, $color, $animal) = explode('|', $line);
To create/define more _friendly_ variables to play with.
Related manual entries are as follows :
explode -- Split a string by string
file -- Reads entire file into an array
II. Array Functions
Was this answer helpful?
The apathetic response is, of course, "there is no point." If you allowed a login over normal...
Check out the "Program Execution functions" here :...
First, we must assume that you are currently storing the username/login, password and the email...
Well, try this.The official PHP web site as a lot of useful information: ...