Jump to content

Tindrop

New Members
  • Posts

    3
  • Joined

  • Last visited

Tindrop's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Barand Many thanks for your answer. Much appreciated! If I was manually creating the array I would know to do an array containing all the Regions I could think of. And do it the way you have suggested. In this case I have scanned (glob) all the image names in a folder that have been named in a certain way (naming protocol) i.e 'some_named_image_(filtername).jpg' In my code (part that you don't see) I have created a list by extracting all the various words (filtername) that lie between the brackets. (in my code this filtername list is the variable '$truncFilter') This is because I want to then create another list of unique values to populate a dynamic dropdown, namely a list with all the filternames included, just once, for each filtername. I have managed to do that but the filternames are including multiple duplicate values depending on how many matching filternames in the image names have been entered between the brackets of all the image names. In this case there are four images. 1 with Glasgow extracted between the brackets and 3 with, for example purposes, Edinburgh. I want to find a way to have just 1 Glasgow and 1 Edinburgh, and 1 of whatever else is found, in my drop down list to use as a filter. Stripping out all duplicates. If you look at my code I tried using array_unique() but it has no effect. I can't enter the values of the array manually as I don't know what all the filtername values are going to be which have been extracted from the image names. I don't have a pre-conceived list of what filtername values are going to be found in each image name. Hopefully I have explained it ok.
  2. Hi I am new this forum and looking for some much appreciated help with something that has me stumped. I have extracted regions from image names in a directory. example: 'edinburgh_castle_(Edinburgh).jpg' (Extracted Edinburgh from in-between the brackets) So I have a list of Regions, extracted from all the various image names in the directory which I want to populate into a dynamic drop down menu for filtering purposes. Here's my issue... I want there to be only one 'Edinburgh' option appearing in my drop down menu. I don't want duplicates. Here is my code so far. php: [select] $filterByArray2 = array ($truncFilter); $filterByArray = array_unique($filterByArray2, SORT_REGULAR); // sort($filterByArray); echo '<pre>'; var_dump($filterByArray); echo '</pre>'; Produces Result... array(1) {[0]=>string( 7 ) "Glasgow"} array(1) {[0]=>string( 8 ) "Edinburgh"} array(1) {[0]=>string( 8 ) "Edinburgh"} array(1) {[0]=>string( 8 ) "Edinburgh"} A for each loop... foreach ($filterByArray as $key => $value) {echo "$key $value,";} prints out... 0 Glasgow,0 Edinburgh,0 Edinburgh,0 Edinburgh, Can anyone, better than myself, tell me how to return 'Glasgow,Edinburgh' with no duplicates. I'm not sure how to do it when all the $keys are 0? Many thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.