PHP: Zoek script

Gestart doorDylan14 reacties39 weergaven

15 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Hallo,

Ik ben bezig met een nieuw livetrein search class en heb een probleem. Ik wil wanneer je bijvoorbeeld op L zoek dat je alleen stations krijgt die beginnen met de letter L.

Script:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33


public function search($keyword, $filter = "all") {
$keyword = ucwords(strtolower($keyword));

if(trim(strlen($keyword)) <= 4 && $filter != code) {
$searchString = $keyword . "%";
}
elseif($filter == "code") {
$searchString = $keyword;
}
else {
$searchString = "%" . $keyword . "%";
}


$searchQuery = mysqli_query($this->Connection, "
SELECT fullname
FROM station
WHERE fullname LIKE "
.mysqli_real_escape_string($this->Connection, $searchString)."
OR midname LIKE "
.mysqli_real_escape_string($this->Connection, $searchString)."
OR smallname LIKE "
.mysqli_real_escape_string($this->Connection, $searchString)."
OR code LIKE "
.mysqli_real_escape_string($this->Connection, $searchString)."
LIMIT 25
"
);

if(mysqli_num_rows($searchQuery) >= 1) {
$results = array();
while ($row = mysqli_fetch_assoc($searchQuery)) {
$results[] = $row["fullname"];
}

return $results;
}
else {
return FALSE;
}
}
}


Nu krijg ik dus als output:
Array ( [0] => Amsterdam Lelylaan [1] => Den Haag Laan v NOI [2] => Geleen-Lutterade [3] => Lage Zwaluwe [4] => Landgraaf [5] => Leerdam [6] => Leeuwarden [7] => Leeuwarden Achter d Hoven [8] => Leeuwarden Camminghaburen [9] => Leiden Centraal [10] => Leiden Lammenschans [11] => Lelystad Centrum [12] => Lichtenvoorde-Groenlo [13] => Lochem [14] => Loppersum [15] => Lunteren [16] => Nijmegen Lent [17] => Onze Lieve Vrouwe t. Nood [18] => Rotterdam Lombardijen [19] => Utrecht Leidsche Rijn [20] => Utrecht Lunetten )

Hoe kan ik dit oplossen? Iets met regel 5 alleen werkt dat niet?

- Dylan
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Weet je waar % voor staat?
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Milan schreef:
Weet je waar % voor staat?
Ja.

Als ik L invoer moet $searchString = L% worden. (regel 6 alleen werkt dat niet)
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] search[COLOR= #007700]([/COLOR][COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$filter[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"all"[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$keyword[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/ucwords"]ucwords[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700]));[/COLOR]

        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700])) <=[/COLOR] [COLOR= #0000BB]4[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$filter[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #DD0000]code[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$searchString[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$keyword[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"%"[/COLOR][COLOR= #007700];
        }[/COLOR] [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$filter[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]"code"[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$searchString[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700];
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$searchString[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"%"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$keyword[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"%"[/COLOR][COLOR= #007700];
        }[/COLOR]
        
        [COLOR= #0000BB]$searchQuery[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_query[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #DD0000]"
        SELECT fullname
        FROM station
        WHERE fullname LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        OR midname LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        OR smallname LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        OR code LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        LIMIT 25
        "[/COLOR][COLOR= #007700]);[/COLOR]
                
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR]mysqli_num_rows[COLOR= #007700]([/COLOR][COLOR= #0000BB]$searchQuery[/COLOR][COLOR= #007700]) >=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR]
                    [COLOR= #0000BB]$results[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
                    [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_fetch_assoc[COLOR= #007700]([/COLOR][COLOR= #0000BB]$searchQuery[/COLOR][COLOR= #007700])) {[/COLOR]
                        [COLOR= #0000BB]$results[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"fullname"[/COLOR][COLOR= #007700]];
                    }[/COLOR]
                    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$results[/COLOR][COLOR= #007700];
                }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
                    [URL="http://www.php.net/return"]return[/URL] FALSE[COLOR= #007700];
                }
    }    
}[/COLOR]


toevoeging op 12 oktober 2013, 12:26:01:
Toevoeging: Die % (Wildcards in SQL) moeten in je query, dus niet in je variable.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Jponsen schreef:
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] search[COLOR= #007700]([/COLOR][COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$filter[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"all"[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$keyword[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/ucwords"]ucwords[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strtolower"]strtolower[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700]));[/COLOR]

        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700])) <=[/COLOR] [COLOR= #0000BB]4[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$filter[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #DD0000]code[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$searchString[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$keyword[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"%"[/COLOR][COLOR= #007700];
        }[/COLOR] [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$filter[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]"code"[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$searchString[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$keyword[/COLOR][COLOR= #007700];
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$searchString[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"%"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$keyword[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"%"[/COLOR][COLOR= #007700];
        }[/COLOR]
        
        [COLOR= #0000BB]$searchQuery[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_query[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #DD0000]"
        SELECT fullname
        FROM station
        WHERE fullname LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        OR midname LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        OR smallname LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        OR code LIKE %"[/COLOR][COLOR= #007700].[/COLOR]mysqli_real_escape_string[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]Connection[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$searchString[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"%
        LIMIT 25
        "[/COLOR][COLOR= #007700]);[/COLOR]
                
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR]mysqli_num_rows[COLOR= #007700]([/COLOR][COLOR= #0000BB]$searchQuery[/COLOR][COLOR= #007700]) >=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]) {[/COLOR]
                    [COLOR= #0000BB]$results[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
                    [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] mysqli_fetch_assoc[COLOR= #007700]([/COLOR][COLOR= #0000BB]$searchQuery[/COLOR][COLOR= #007700])) {[/COLOR]
                        [COLOR= #0000BB]$results[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"fullname"[/COLOR][COLOR= #007700]];
                    }[/COLOR]
                    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$results[/COLOR][COLOR= #007700];
                }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
                    [URL="http://www.php.net/return"]return[/URL] FALSE[COLOR= #007700];
                }
    }    
}[/COLOR]
toevoeging op 12 oktober 2013, 12:26:01:
Toevoeging: Die % (Wildcards in SQL) moeten in je query, dus niet in je variable.

Dat werkt gewoon hoor:

Codeblok (echo):

1

SELECT fullname FROM station WHERE fullname LIKE L% OR midname LIKE L% OR smallname LIKE L% OR code = L% LIMIT 25
Afbeelding

Hij zou alleen nu de stations moeten weergeven die met L beginnen.

toevoeging op 12 oktober 2013, 141643:
Naja heb zo opgelost; niet echt zo als ik het wou maarja het werkt wel:

Codeblok (voorbeeld.php):

1
2
3
4
5
6


while ($row = mysqli_fetch_assoc($searchQuery)) {
if($row["fullname"][0] == $keyword[0]) {
$results[] = $row["fullname"];
}
}
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dit is idd niet een mooie oplossing.

Wat je zou kunnen proberen is verschillende functies te maken

class Search
// public search sting
// public search options

// hier een algoritmes

Een goeie zoekmachine kan sowieso niet alle functies in één query (of eigenlijk één functie) hebben.

Ik heb wel eens een zoekmachine voor een forum geschreven, dat werd uiteindelijk een class van ruim 200 regels.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Wat rogier zegt inderdaad. Je gaat nu een class maken waar één functie in zit met verschillende filters. Een goede class, en een goede functie, laat elke functie (lees: filter) door een aparte functie afhandelen (klinkt raar, i know)

Dat wil zeggen dat je functies krijgt zoals:
searchByFirstLetter (= $input %)
searchByKeyword (= % input %)
searchExact (= $input)

Dat is veel netter en overzichtelijker.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Zo iets dus:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


public function searchByFirstLetter($keyword) {
$searchQuery = mysqli_query($this->Connection, "
SELECT fullname,code
FROM statoin
WHERE fullname LIKE "
.mysqli_real_escape_string($keyword)."%
OR midname LIKE "
.mysqli_real_escape_string($keyword)."%
OR smallname LIKE "
.mysqli_real_escape_string($keyword)."%
ORDER BY fullname ASC
LIMIT 25;
"
);

if(mysqli_num_rows($searchQuery) >= 1) {
$results = array();
while($row = mysqli_fetch_assoc($searchQuery)) {
$results["fullname"][] = $row["fullname"];
$results["code"][] = $row["code"];
}

return $results;
}
else {
return FALSE;
}
}


toevoeging op 12 oktober 2013, 17:40:26:
Nope werkt niet:
$test = new Search();
print_r($test->searchByFirstLetter(l));

Codeblok (voorbeeld.php):

1

Array ( [fullname] => Array ( [0] => Amsterdam Lelylaan [1] => Den Haag Laan v NOI [2] => Lage Zwaluwe [3] => Landgraaf [4] => Leerdam [5] => Leeuwarden [6] => Leeuwarden Achter d Hoven [7] => Leeuwarden Camminghaburen [8] => Leiden Centraal [9] => Leiden Lammenschans [10] => Lelystad Centrum [11] => Lichtenvoorde-Groenlo [12] => Lochem [13] => Loppersum [14] => Lunteren [15] => Nijmegen Lent [16] => Onze Lieve Vrouwe t. Nood [17] => Rotterdam Lombardijen [18] => Utrecht Leidsche Rijn [19] => Utrecht Lunetten )
 => Array ( [0] => ASDL [1] => LAA [2] => ZLW [3] => LG [4] => LDM [5] => LW [6] => ADH [7] => LWC [8] => LEDN [9] => LDL [10] => LLS [11] => LTV [12] => LC [13] => LP [14] => LTN [15] => NML [16] => OLV [17] => RLB [18] => UTLR [19] => UTL ) )


toevoeging op 12 oktober 2013, 17:55:26:
Dan maar zo, dit werkt wel. Dit is wel een goede manier toch?

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

public function searchByFirstLetter($keyword, $field = "fullname") {
$searchQuery = mysqli_query($this->Connection, "
SELECT fullname,code
FROM station
WHERE "
.$field." LIKE ".mysqli_real_escape_string($this->Connection, $keyword)."%
ORDER BY fullname ASC
LIMIT 25;
"
);

if(mysqli_num_rows($searchQuery) >= 1) {
$results = array();
while($row = mysqli_fetch_assoc($searchQuery)) {
$results["fullname"][] = $row["fullname"];
$results["code"][] = $row["code"];
}

return $results;
}
else {
return FALSE;
}
}
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
correct, echter kan je nu niet meerdere filters toepassen.

Daarbij is wat je nu doet alleen resultaten ophalen. Je wilt bij een goeie zoekmachine ervoor zorgen dat er gesorteerd kan worden op relevantie enzo...
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Heb nu een vaag probleem:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


public function searchByFirstLetter($keyword, $field = "fullname") {
$searchQuery = mysqli_query($this->Connection, "
SELECT fullname,code
FROM station
WHERE "
.$field." LIKE ".mysqli_real_escape_string($this->Connection, $keyword)."%
ORDER BY fullname ASC
LIMIT 25;
"
);

$results = array();
while($row = mysqli_fetch_assoc($searchQuery)) {
$results["fullname"] = $row["fullname"];
$results["code"] = $row["code"];
}

return $results;
}


$test = new Search();
print_r($test->searchByFirstLetter(l));

Als ik de SQL in pma uitvoer krijg ik 13 resultaten, en van het script maar 1:

Array ( [fullname] => Lunteren [code] => LTN )
[/code]

Terwijl ik toch echt while(); gebruik.
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je overwrite nu elke waarde in de array, je moet dit doen $results[][fullname] =

Dan krijg je zoiets als dit:

array ( [0] => array(fullname => henk), [1] => array(fullname => henk))

toevoeging op 18 oktober 2013, 13:37:21:
Je doet nu eigenlijk dit:

while() { $var = $henk; }

Dan krijg je dus alleen de laatste waarde omdat je de var de hele tijd overwrite.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Ooh, ik dacht dat array`s niet overwrite`de. Nu heb ik een ander probleem waarbij ik niet weet wat ik moet doen; ik heb namelijk bijvoorbeeld dit"

Codeblok (voorbeeld.php):

1
2

$test = new Search();
print_r($test->search(leeuwarden));

Output:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14

Array ( [fullname] => Array ( [0] => Leeuwarden [1] => Leeuwarden Achter d Hoven [2] => Leeuwarden Camminghaburen [3] => Leeuwarden [4] => Leeuwarden Achter d Hoven [5] => Leeuwarden Camminghaburen [6] => Leeuwarden [7] => Leeuwarden )
 => Array ( [0] => LW [1] => ADH [2] => LWC [3] => LW [4] => ADH [5] => LWC [6] => LW [7] => LW ) )


en misschien raad je het al, ik wil alle dubbele ik wil overal maar 1 van hebben, ik heb al rond gezocht op google maar ik krijg alleen dat ik dan dit heb:

[fullname][4] => Leeuwarden
[fullname][7] => Leeuwarden Achter d Hoven

etc.

Ik wil dus dat die getallen 1,2,3 blijft anders klopt het niet meer.

toevoeging op 18 oktober 2013, 22:02:32:
Fixed.
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Kan gewoon met array_unique() ?
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Rogier schreef:
Kan gewoon met array_unique() ?
Ja maar dan reset die de index niet, maar het is is al fixed.

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8

private function arrayUnique ( $rArray ){
$rReturn = array ();
while ( list( $key, $val ) = each ( $rArray ) ){
if ( !in_array( $val, $rReturn ) )
array_push( $rReturn, $val );
}
return $rReturn;
}
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
array_values(array_unique()) ofzo zou dan toch ook kunnen?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren