I have an array (for example, such). The structure is unknown to me, I only know that the array consists of the nth number of rows.

Array ( [workers] => Array ( [worker1] => "John" [worker2] => "Matthew" [worker3] => "Andrew" ) ) 

The task is to filter the lines. For example, I can do this - 'first_name' => filter_input( INPUT_POST, 'first_name', FILTER_SANITIZE_STRING ) for a string (one single!). This will not drive to the array. I can use filter_input_array, but then $ args will have to describe each line and what to apply to it (which filter). And if there are n lines of such lines, which I cannot track?

    1 answer 1

    There are many options for filtering arrays. Here is one example.

     <?php $arr = [ 'workers' => [ 'worker1' => '<h6>John</h6>', 'worker2' => '<h5>Matthew</h5>', 'worker3' => '<h4>Andrew</h4>' ], 'workers2' => [ 'worker1' => '<h3>John</h3>', 'worker2' => '<h2>Matthew</h2>', 'worker3' => [ 'worker1' => '<h3>John</h3>', 'worker2' => '<h2>Matthew</h2>', 'worker3' => '<h1>Andrew</h1>' ] ] ]; // До фильтра echo '<pre>'; var_dump($arr); echo '</pre>'; array_walk_recursive($arr, function(&$item, $key) { $item = strip_tags($item); }); // После фильтра echo '<pre>'; var_dump($arr); echo '</pre>';