Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get json kay value php

$arr = json_decode($json, true);
 
// Loop through the associative array
foreach($arr as $key=>$value){
    echo $key . " => " . $value . "<br>";
}
Comment

php return json

header('Content-type: application/json');
echo json_encode($array);
Comment

php read json request body

//e.g your JSON Req is like this {"UserName":"Ranish","Password":"asdasdasd"}
$jsonReqUrl  = "php://input";
$reqjson = file_get_contents($jsonReqUrl);
$reqjsonDecode = json_decode($reqjson, true);
echo $reqjsonDecode['UserName'];
Comment

php json request get value

<?php
$jsonurl = "https://reqres.in/api/users/2";
$json = file_get_contents($jsonurl);
$jsonDecode = json_decode($json, true);
echo $jsonDecode['data']['email'];
?>
Comment

php json request get value of an array element

<?php
$jsonurl = "https://reqres.in/api/users?page=2";
$json = file_get_contents($jsonurl);
$jsonDecode = json_decode($json, true);
var_dump($jsonDecode['data']);
foreach($jsonDecode['data'] as $mydata){
    echo $mydata['email'] . "<br>";
}
?>
Comment

php return json data

header('Content-Type: application/json'); 

$colors = array("red","blue","green");
echo json_encode($colors);
Comment

php return a json response

//PHP File
<?php
$data = /** whatever your data are **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);

//In JS File
//JQUERY AJAX
        $.ajax({
        url: "path/to_php_file.php",
        dataType: "json",  
        type: "GET",
        data: {datax : datax },
Comment

return json in php

//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
Comment

PREVIOUS NEXT
Code Example
Php :: Magento 2 -Limit the length of the product name on the front end. 
Php :: php select page change 
Php :: operador in laravel 
Php :: laravel php 8 ububtu 
Php :: Laravel - create model, controller and migration in single artisan command 
Php :: minuscule chaine php 
Php :: laravel join with multiple conditions 
Php :: fore install debian 10 php 7.3 
Php :: how to add new column in laravel migration 
Php :: install php linux nginx command line 
Php :: php is scan dir recursive? 
Php :: adding column to array php 
Php :: check string php 
Php :: set php path in ubuntu 
Php :: laravel websockets onclose 
Php :: php odd or even 
Php :: How do I get PHP errors to display 
Php :: composer larave install version 
Php :: delete all rows in table laravel 
Php :: laravel get last get request 
Php :: phpunit repeat 
Php :: php current page url 
Php :: php multi type parameter union types 
Php :: php array_reverse keep keys 
Php :: wherein laravel 
Php :: render vs redirect laravel exception 
Php :: format time laravel 
Php :: how to loop array in laravel 
Php :: setcookie 
Php :: php date format iso 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =