“PHP Convert Array ke JSON Object” Kode Jawaban

PHP Convert Array ke JSON Object

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

$toJSON = json_encode($myArr);

echo $toJSON;
Lazy Loris

json ke 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);
Splendid Salmon

data php json ke 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.
Borma

json ke array php

<?php
        $json = '[{"name":"xxx","phone":"123","email":"[email protected]"},{"name":"yyy","phone":"456","email":"[email protected]"},{"name":"zzz","phone":"678","email":"[email protected]"}]';
        $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>';
      ?>
Fierce Fly

cara mengubah array menjadi json php

convert data
Troubled Turkey

Jawaban yang mirip dengan “PHP Convert Array ke JSON Object”

Pertanyaan yang mirip dengan “PHP Convert Array ke JSON Object”

Lebih banyak jawaban terkait untuk “PHP Convert Array ke JSON Object” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya