0

I have following code in my contoller:

public function actionForm($id)
    {
        $jsonfile=ChForms::model()->findByPk($id);
        $decodedJson=json_decode($jsonfile->json, true);
        var_dump($decodedJson);
        return $decodedJson;
    }

Here json ( in $jsonfile->json) is name of the field in ChForms. When I wrote `var_dump($decodedJson);, it showed the data below:

array(38) { ["name"]=> string(10) "membership" ["view"]=> string(14) "pdf/membership" ["phone"]=> string(5) "22222"

I am going to display it in the following way:

name: membership
view: pdf/membership
phone: 22222

How can I do it?

phpdev
  • 511
  • 4
  • 22

1 Answers1

1

You can use foreach():

foreach ($decodedJsonas as $key => $value) {
        echo "$key: $value \n";
    }

You can see how it works below:

PHP Compiler

Karol Gasienica
  • 2,825
  • 24
  • 36