Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php convert array to json object

$myArr = array("apple", "banana", "mango", "jackfruit");

$toJSON = json_encode($myArr);

echo $toJSON;
Comment

json to array php

//2 ways
  //this is for string from $_REQUEST,$_POST to array
$jsonText = $_REQUEST['myJSON'];
$decodedText = html_entity_decode($jsonText);
$myArray = json_decode($decodedText, true);

//this is for json to array
$assosiative_array = json_decode(json_encode($jsonText),true);
Comment

How to JSON encode a PHP array

<?php
	// the php array
  	$array = array();
	$array['key1'] = "value1";
	$array['key2'] = "value2";
	$array['key3'] = "value3";

	// encode the php array into JSON format
	$json = json_encode($array);

	// check out the results
	var_dump($json);
?>
Comment

how to receive json data in php

$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
Comment

json to php array

<?php
        $json = '[{"name":"xxx","phone":"123","email":"a@a.com"},{"name":"yyy","phone":"456","email":"b@a.com"},{"name":"zzz","phone":"678","email":"c@a.com"}]';
        $json_decoded = json_decode($json);
        echo '<table>';
        foreach($json_decoded as $result){
          echo '<tr>';
            echo '<td>'.$result->name.'</td>';
            echo '<td>'.$result->phone.'</td>';
            echo '<td>'.$result->email.'</td>';
          echo '</tr>';
        }
        echo '</table>';
      ?>
Comment

php json data to array

json_decode('{foo:"bar"}');         // this fails
json_decode('{"foo":"bar"}', true); // returns array("foo" => "bar")
json_decode('{"foo":"bar"}');       // returns an object, not an array.
Comment

json php

<?php
header("Content-Type: application/json; charset=utf-8");
if (!empty($_REQUEST['q'])){
    $q = $_REQUEST['q'];
    require_once('api-key.php');
    $apiUrl = "http://api.openweathermap.org/data/2.5/weather?q=" . $q . "&lang=fr&units=metric&APPID=" . API_KEY;
  
    $response = file_get_contents($apiUrl, False);
    $data = json_decode($response, true); // $data = TABLEAU PHP
  
    setLocale(LC_TIME,"fr_FR.UTF-8");
    date_default_timezone_set("Europe/Paris");
    $today = strftime('%A %d %B %y',time());
    $hour = date('H:i:s');
    // on prépare un tableau $json pour la réponse
    $json =  array("lieu" => $q,
                   "jour" => $today, 
                   "heure"=> $hour,
                   "meteo"=> array());
    $json['meteo']['main'] = $data['main'];
    $json['meteo']['description'] = $data['weather'][0]['description'];
    $json['meteo']['id'] = $data['weather'][0]['id'];
    echo json_encode($json,JSON_PRETTY_PRINT);
   }
Comment

php convert array to json

{} = json_encode([]);
Comment

return json in php

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

php object to json

function getJsonData(){
    $var = get_object_vars($this);
    foreach ($var as &$value) {
        if (is_object($value) && method_exists($value,'getJsonData')) {
            $value = $value->getJsonData();
        }
    }
    return $var;
}
Comment

json en php

{"data":[
 { "sub_data1":"value1", "sub_data2":"value2","sub_data_n":"value n" },
 { "sub_data2":"value2","sub_data2":"value2", "sub_data_n":"value n" },
 { "sub_data n":"value n ", "sub_data2":"value2","sub_data_n":"value n" }
]}
Comment

PREVIOUS NEXT
Code Example
Php :: php throw fatal error 
Php :: nested loop in php 
Php :: Creating dynamic subdomain in php 
Php :: Laravel 7 pagination with search filter 
Php :: php round function syntax 
Php :: insert javascript in php 
Php :: base64_img 
Php :: php regex named groups 
Php :: php pass a function as a parameter 
Php :: Call to undefined method IlluminateDatabaseEloquentRelationsHasMany::attach() 
Php :: restart php service windows 
Php :: doctrine where 
Php :: php arrays 
Php :: oop php 
Php :: laravel project composer [ErrorException] Undefined index: name 
Php :: how to run a php file using 
Php :: laravel.com relationship 
Php :: :: in php 
Php :: download html table to excel 
Php :: wordpress add action 
Php :: laravel request query logger 
Php :: different between two dates 
Php :: php array form 
Php :: symfony functional test clear session and cookies 
Php :: notify in piperx 
Php :: how to set default php version in ubuntu 
Php :: SymfonyStyle 
Php :: file_get_contents max_execution_time 
Php :: generate rand password php 
Php :: IlluminateDatabaseEloquentMassAssignmentException with message 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =