Views php field table sorting error
Review this post

You will find there is a value box and a output box. 

Your code above suggest you are doing the display from the value box and that won't work.

move most of your code to the value box and then end with:

value = $stockex[2];


then paste 

&lt;?php
    print $value
    ?&gt;  

in the output box. 

Good Luck!