Wednesday, 20 July 2016

Passing JSON into php function as a parameter

Here is an example of hot to pass JSON into a php function as a parameter:

<?php

function print_details($json) {
 $args = json_decode($json);
 
 echo "My first name is {$args->first_name}<br />"; 
 echo "My last name is {$args->last_name}<br />"; 
 echo "My age is {$args->age}<br />";  
}


print_details('{
  "first_name": "keith",
  "last_name": "hards",
  "age": 37
}');
 

No comments:

Post a Comment