-1

I need to convert

h this 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"]]

to a array, including nesting, in 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',
  ),
)

Once converted to an object in PHP I need to be able to access / find the "theory of relativity" in the object.

1 Answers1

1

You should use https://www.php.net/manual/en/function.json-decode.php

Example:

$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));

Q: how to access to "theory of relativity" ?:

A:

$data = json_decode($myJson);
echo $data[1][1];
milempicki
  • 11
  • 2