Question: I have a robot stock trading program that I've been working on for a few months. The other day though I added a 2nd condition to the code that determines when the trade gets exited. Condition as follows:

```
decimal entryPrice;
decimal CurrentPrice;
decimal openShares;

if ((1st condition) && (((entryPrice - CurrentPrice) * openShares) >= 8))

```

Today was the first day the situation came up, and I happened to have the day off work so I was observing the trades. The condition didn't trigger though. The trade kept going until I manually exited.

What should have happened is that it would subtract the current price from the price at time of entry, then multiply that by the number of shares to get the current profit. And if it's greater than or equal to 8, it triggers. This particular code was only for exiting short trades, so subtracting the current price from the entry price should return a positive value. 

I verified in my code that the entryPrice was being logged at time of purchase. So all I can think is that I'm messing something up with the condition format. Either it doesn't like the bracket arrangement or the resulting number value types aren't compatible with each other. Does anything jump out at you? Thanks.

Answer: 
Actually your code is right till the last line of javascript code which is:-

```
document.getElementById("demo").innerHTML = result.hotels[0].codigo + " " + result.hotels[0].estado;

```

Change it to:-

```
document.getElementById("demo").innerHTML = result.hotels.codigo+ " " + result.hotels.estado;

```

Example:-

```
<?php 

$result = Array
(
    'hotels' => Array
        (
            'codigo' => 'LIMHBM',
            'fecha' => '2016/9/15',
            'cannoc' => 1,
            'canhab' => 1,
            'canpax' => 2,
            'estado' => 'OK'
        )

);
?>
1) Results of PHP array print
<?php echo "<pre/>";print_r($result); ?>

2) Results of JSON parse: 
<span id="demo">none</span>

<script type="text/javascript">
var result =  JSON.parse('<?php echo json_encode($result) ?>');
console.log(result); // to just show you te output in console
document.getElementById("demo").innerHTML = result.hotels.codigo+ " " + result.hotels.estado;
</script>

```

Output:- <http://prntscr.com/avm729>

For multidimensional array help, check this:-

<http://prntscr.com/avmcp3>
This bit is pointless:

```
var result = JSON.parse( '<?php echo json_encode($result) ?>' );

```

JSON is already valid javascript, so there's **NO** need to parse it. All you need to do is dump it out directly into the code block:

```
var result = <?php echo json_encode($result); ?>;

```