-1

how to get the ["text"]=> string(4) "head" value to the php variable

From the below json

var_dump($result)

https://i.stack.imgur.com/0M0YR.png

Peter
  • 8,776
  • 6
  • 62
  • 95
Vivek ab
  • 660
  • 6
  • 15

2 Answers2

4

This should do it:

$result->tuc[0]->phrase->text;

You should really post the var_dump result in your question, and not just link to it, so the q&a remains on SO.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
1

To handle json, PHP offers the json_encode and json_decode functions.

Encoding

$array = [
    'key' => 'value'
];

$jsonString = json_encode($array);

Decoding

// Decoding will make your json into an object
// If you require json_decode() to output an array,
// you should pass true as a second parameter
$object = json_decode($jsonString);
$array = json_decode($jsonString, true);

// To access a value
echo $json->key;

Resources

Peter
  • 8,776
  • 6
  • 62
  • 95