[PHP] filter_input multidimensional arrays

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • Tsjilp
  • Registratie: November 2002
  • Niet online
Ik heb de volgende array die via POST binnenkomt:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[projects] => Array (
        [0] => Array
            (
                [description] => description 1
                [path] => url 1
            )

        [1] => Array
            (
                [description] => description2
                [path] => url 2
            )

        [2] => Array
            (
                [description] => description 3
                [path] => url 3
            )

    )


Deze input wil ik filteren met de ingebouwde filter functionaliteit:

PHP:
1
2
$fields = array('projects' => array('filter' => FILTER_CALLBACK,'flags' => FILTER_FORCE_ARRAY, 'options' => array($this, 'cleanProjects'));
filter_var_array($_POST, $fields);


Je zou verwachten dat cleanProjects 3x wordt aangeroepen, echter, cleanProjects wordt voor elke string in de array aangeroepen (dus 6x). Wat ik wil is dat hij per 'project' wordt aangeroepen.
Iemand een idee hoe ik dit kan bewerkstelligen?

Raar... Is zo gek nog niet


Acties:
  • 0 Henk 'm!

  • Aloys
  • Registratie: Juni 2005
  • Niet online
Zou je niet een combinatie van array_map/array_walk en filter_var kunnen doen?

Acties:
  • 0 Henk 'm!

  • Tsjilp
  • Registratie: November 2002
  • Niet online
Ik heb het inmiddels al anders opgelost. Via stackoverflow was ik er reeds achter gekomen dat filter_input niet met multidimensionale arrays om kan gaan.
Ik heb ik json-encode $_POST['projects'] nu voor het filter_input, in de callback decode ik het weer.

Raar... Is zo gek nog niet