Hi.
Im trying to build a filtering system for a imagegallery in PHP. I want to be able to filter out images by category with checkboxes. What I´m currantly working on is reading data from a text file into an multidimensional array that I will later use to instantiate objects of a class and echo out each image.
I guess i have to use a foreach loop to explode each data into the array, but I´m not sure how to assign each data to the right array index.
I am thinking the array should look like this: (But please correct me if this dosent seem right)
[code]$images = array(array(“srcFile”=> “image1.jpg”, “thumbFile”=> “image1_250x250.jpg”, “altTag”=> “waterfall”,
“animal”=> false, “nature”=> true, “architecture”=> false),
array(“srcFile”=> “image2.jpg”, “thumbFile”=> “image2_250x250.jpg”, “altTag”=> “bridge”,
“animal”=> false, “nature”=> false, “architecture”=> true),
array(“srcFile”=> “image3.jpg”, “thumbFile”=> “image3_250x250.jpg”, “altTag”=> “dog”,
“animal”=> true, “nature”=> false, “architecture”=> false)
);
This is what I have so far:
[code]
// Get datalines from file
$lineContent = explode(“n”, file_get_contents(‘./data.txt’));
// Split each dataline into datafields
foreach ($lineContent as $l) {
$arrayFields = explode(“|”, $l );
foreach ($arrayFields as $i) {
// Some code to assign data to right array index.
}
}