如何在PHP中转换一个嵌套的JSON数组[重复]。

问题描述 投票:-1回答:1

我需要转换

这个 JSON。

["theory",["theory","theory of relativity","theory test","theory of everything","theory definition","theory of evolution","theory of mind","theory of a deadman","theory of love","theory meaning"]]

转换为一个数组,包括嵌套,在PHP中。

array (
  0 => 'theory',
  1 => 
  array (
    0 => 'theory',
    1 => 'theory of relativity',
    2 => 'theory test',
    3 => 'theory of everything',
    4 => 'theory definition',
    5 => 'theory of evolution',
    6 => 'theory of mind',
    7 => 'theory of a deadman',
    8 => 'theory of love',
    9 => 'theory meaning',
  ),
)

一旦在PHP中转换为一个对象,我需要能够访问找到 "相对论 "的对象。

php json var-dump
1个回答
1
投票

你应该使用 https:/www.php.netmanualenfunction.json-decode.php

例子

$myJson = '["theory",["theory","theory of relativity","theory test","theory of everything","theory definition","theory of evolution","theory of mind","theory of a deadman","theory of love","theory meaning"]]';

print_r(json_decode($myJson));

问:如何进入 "相对论"?

A:

$data = json_decode($myJson);
echo $data[1][1];
© www.soinside.com 2019 - 2024. All rights reserved.