Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Use of json_encode() function in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 188
    Comment on it

     Hi Reader's,
     Welcome to FindNerd, today we are going to discuss use of json_encode() function in php.

    json_encode() is used to convert the array given as it's argument into a JSON string. JSON full form is JavaScript Object Notation.

    If you are using json_encode() function then always json_encode() function returns a function when json_encode() function function will work.

    json_encode() function returns a JSON encoded string on success or returns FALSE on failure.

    Syntax of json_encode() function

      

    json_encode(value, options)

    you can see below example:

    <?php
    
    //First you need a PHP array of data
    $result = array(
        'first_name'    =>    "Tom",
        'last_name'    =>    "Gray",
        'phone_number'    =>  123456789,
        'address'    =>    "USA"
    
    );
    //here call json_encode() function
    $jsondata = json_encode($result);
    //print json_encode data
    print_r($jsondata);
    
    ?>

    Output will come following of above example

    {"first_name":"Tom","last_name":"Gray","phone_number":123456789,"address":"USA"}

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: