Q:

How to read json encoded value using php?

I have a variable in PHP, named as $partialSegments. I want to iterate through it and perform actions when I strike operator or rOperandValue, etc. I receive it in a function call, so while making the 
function named(say):
 public function convertJsCode($partialSegments){
//logic
}

I am struggling with the logic
"segments":{"type":"custom","partialSegments":[{"type":"7","operator":11,"rOperandValue":["windows xp"],"prevLogicalOperator":null},{"type":"8","operator":11,"rOperandValue":["other"],"prevLogicalOperator":"AND"}]}}

A:

Use json_decode() function in php
  <?php

$json = '{"segments":{"type":"custom","partialSegments":[{"type":"7","operator":11,"rOperandValue":["windows xp"],"prevLogicalOperator":null},{"type":"8","operator":11,"rOperandValue":["other"],"prevLogicalOperator":"AND"}]}}';

$parsed = json_decode($json, true);

foreach($parsed["segments"]["partialSegments"] as $val) {

    $operator = $val["operator"]; // operator value 
    $rOperandValue = $val["rOperandValue"][0]; // rOperandValue value 

}

?>

