chiprivers Posted May 26, 2007 Share Posted May 26, 2007 I have the following piece of code: <?php // create multi-dimensional array of runners holding selectionId, best back, best lay foreach ($marketPrices as $key => $data) { // extract data to array $temp = array( "selectionId" => $data->selectionId, "priceToBack" => $data->bestPricesToBack->Price[0]->price, "priceToLay" => $data->bestPricesToLay->Price[0]->price ); // add array to multidimensional array $selectionPrices[] = $temp; } // end for each $marketPrices ?> Where print_r($data, true) returns the following: stdClass Object ( [asianLineId] => 0 [bestPricesToBack] => stdClass Object ( [Price] => Array ( [0] => stdClass Object ( [amountAvailable] => 23.49 [betType] => L [depth] => 1 [price] => 5.7 ) [1] => stdClass Object ( [amountAvailable] => 23.62 [betType] => L [depth] => 2 [price] => 5.5 ) [2] => stdClass Object ( [amountAvailable] => 10 [betType] => L [depth] => 3 [price] => 5.2 ) ) ) [bestPricesToLay] => stdClass Object ( [Price] => Array ( [0] => stdClass Object ( [amountAvailable] => 6.5 [betType] => B [depth] => 1 [price] => 5.8 ) [1] => stdClass Object ( [amountAvailable] => 41.8 [betType] => B [depth] => 2 [price] => 5.9 ) [2] => stdClass Object ( [amountAvailable] => 10 [betType] => B [depth] => 3 [price] => 6 ) ) ) [handicap] => 0 [lastPriceMatched] => 5.7 [reductionFactor] => 18.9 [selectionId] => 10655 [sortOrder] => 0 [totalAmountMatched] => 1463.56 [vacant] => ) When I am running the script, I get this fault: Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\BFAuto\selectionLayer.php on line 61 Line 61 is: "priceToLay" => $data->bestPricesToLay->Price[0]->price ANy idea what is causing the problem here? I have the same construct, which I think is right, in the previous line and does not throw up an error! I am reasonably new to using objects so I may be wrong! Link to comment https://forums.phpfreaks.com/topic/53043-stumped/ Share on other sites More sharing options...
Dragen Posted May 26, 2007 Share Posted May 26, 2007 I may be wrong, but I believe you've missed out the ',' at the end of the line. "priceToLay" => $data->bestPricesToLay->Price[0]->price, Link to comment https://forums.phpfreaks.com/topic/53043-stumped/#findComment-262023 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 whats the results of echo "<pre>"; print_r($data->bestPricesToLay->Price); print_r($data->bestPricesToLay->Price[0]); EDITED BY WILDTEEN88: Please use the code tags ( ) tags when posting code in posts. Thank you. Link to comment https://forums.phpfreaks.com/topic/53043-stumped/#findComment-262038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.