Jump to content

STUMPED!


chiprivers

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.