I am storing all of my items into lines in a text file like so, with the ID at the start
1/item name/content/etc
2/item name/content/etc
3/item name/content/etc
4/item name/content/etc
This method of storage is for a simple script we are using on a game that is editable by the different users so security really isn't a big deal, or else we would just use mysqli and the like.
I need to be able to print out variable information for a single entry, found by the id at the beginning, and also print say, 3 and 2, in numerical order. So far I am loading them into an array like so
$content = file('script/items.txt');
$items = array($content);
it throws the whole file into an array like this
array(1) {
[0]=> array(4) {
[0]=> string(23) "1/item name/content/etc"
[1]=> string(23) "2/item name/content/etc"
[2]=> string(23) "3/item name/content/etc"
[3]=> string(23) "4/item name/content/etc"
}
}
is there an easier way to pick one, or even multiple using just their id so i don't have to store the whole file into the array (it could get big in the future) or is the best way to store them all, loop through the entire array one line at a time, explode them for each /, and them compare is it's in the required items? Thanks.
$items = array($content);and loop over$contentarray itself. Best is to move to database