Join WhatsApp ChannelJoin Now

How To Use Json In PHP Example

Hi Dev,

Today, i we will show you how to use json in PHP example. This article will give you simple example of how to use json in PHP example. you will learn how to use json in PHP example.

php has some built-in functions to handle json to given two function in php.

-json_encode()

-json_decode()

So let’s follow few step to create example of how to use json in PHP example.

json_encode()

<!doctype html>
<html>
    <body>
    <?php
        $age = array("php"=>35, "laravel"=>37, "html"=>43);
        echo json_encode($age);
    ?>
    </body>
</html>

Output:

{"php":35,"laravel":37,"html":43}

json_decode()

<!doctype html>
<html>
    <body>
    <?php
        $jsonobj = '{"php":35,"laravel":37,"html":43}';
        print_r(json_decode($jsonobj));
    ?>
    </body>
</html>

Output:

stdclass object ( [php] => 35 [laravel] => 37 [html] => 43 )

Recommended Posts