1

I want to loop through an multidimensional array, which has multiple keys and arrays of strings assigned to the keys. For each string in the arrays, I want to execute the strip_tags function and replace the old string with the new one.

I am very new to php and I am very confused.

So thanks for your help!

EDIT:

This is what I did so far:

<?php
include ('../db.php');


$sql = "select id, post_title, post_content, post_type, post_date from wp_posts where post_type = 'post' order by post_date desc limit 20";
$ergebnis = $db->query($sql);

$zeile = $ergebnis->fetchALL(PDO::FETCH_ASSOC);

$keys = array_keys($zeile);

$valuearray = array();


for($i=0; $i < count($keys); $i++) {

    foreach($zeile[$keys[$i]] as $key => $value) {
    if(is_string($value) == true) {
        $value1 = strip_tags($value);
        array_push($valuearray, $value1);
        $zeile[$keys[$i]] = $valuearray;
     }
    else {
        array_push($valuearray, $value);
        $zeile[$keys[$i]] = $valuearray;        
        }
 }
}
    


$json = json_encode($zeile);

echo $json;

?>

I need the output as json for flutter development.

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.