简体   繁体   English

如何使用PHP以JSON格式打印数据

[英]How to Print data in JSON format using PHP

PHP code : PHP代码:

print_r($InformationRetrieval['KeywordExtraction'][1]);

Outputs : 输出:

Array
(
    [google] => 15
    [search] => 18
    [or] => 2
    [web] => 4
    [is] => 4
    [a] => 5
    [engine] => 2
}

but needs to print words that are indexes of this array eg: google, search, or, web etc.. 但需要打印作为该数组索引的单词,例如:google,搜索或网络等。

How is it done? 怎么做?

You can use array_keys ; 您可以使用array_keys ;

print_r(array_keys($InformationRetrieval['KeywordExtraction'][2]));

Here is a working demo: Demo 这是一个工作示例: 演示

use this : 用这个 :

<?php
$a = array("google" => 15, "search" => 18, "or" => 2, "web" => 4, "is" => 4, "a" => 5, "engine" => 2);

foreach($a as $key=>$value) {
   echo $key;
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM