nested array in php

  • Hallo ich versuche, dieses Array in php zu erstellen:


    trips = {
    "list_trips": [{
    "list_id": "0",
    "name": "Germany",
    "list_type": "0",
    "user_id": "0"
    }, {
    "list_id": "1",
    "name": "Poland-trip",
    "list_type": "1",
    "user_id": "0"
    },
    {
    "list_id": "2",
    "name": "list-Attractions-A",
    "list_type": "0",
    "user_id": "0"
    },
    {
    "list_id": "3",
    "name": "list-attractions-B",
    "list_type": "1",
    "user_id": "0"
    }
    ]
    }



    , durch anhängen von $ listelement. Doch ich glaube mein Ansatz ist falsch. Hier ein Teil meines Codes:


    $list = array(
    'list_trips' => array()

    );

    //show data
    $result = mysqli_query($conn, $sql);

    while ($row = mysqli_fetch_assoc($result)) {
    $list_element = array(
    'list_id' => $row["list_id"],
    'name' => $row["name"],
    'list_type' => $row["list_type"],
    'user_id' => $row["user_id"]
    );

    array_push($list('list_trips'), $list_element);
    }

    echo($list);


    Kann mir jemand sagen, wie es wirklich geht?

    Vielen Dank schonmal

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!