-1

Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code

I am using SOAP to get data from the server and in response i am getting a php array like this

Array
(
 [BookResult] => stdClass Object
 (
  [PNR] => 5WPODU
  [BookingId] => 31149
  [Status] => stdClass Object
   (
    [StatusCode] => 03
    [Description] => Fare is not available at the time of booking
    [Category] => BK
   )
  [SSRDenied] => N
  [ProdType] => Flight
 )
)

All i want to know is how can i extract "PNR" and "StatusCode" value in separate variables so that i can store them in database.

Tried this not working

$p = (object) $array;
echo $p->StatusCode;  
Community
  • 1
  • 1

3 Answers3

4

Try this:

$PNR = $array["BookResult"]->PNR;
$StatusCode= $array["BookResult"]->Status->StatusCode;

$array is an array. So first dive is $array['BookResult']. BookResult is stdClass instance so next goes $array['BookResult']->Status (get object's property). Status is also stdClass instance so get it's property: $array['BookResult']->Status->StatusCode

Bogdan Burym
  • 5,482
  • 2
  • 27
  • 46
0

Assuming results are being stored in $array

echo $array['BookResult']->Status->StatusCode;
echo $array['BookResult']->PNR;
Dr. Dan
  • 2,288
  • 16
  • 19
0
var_dump($array['BookResult']->PNR);   
var_dump($array['BookResult']->Status->StatusCode);
VettelS
  • 1,204
  • 1
  • 9
  • 17