Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.