0

I've been searching around but i'm failing to find an answer to something that seems it should be simple to fix!

I'm reading products from XML and putting their data into an array on a loop, the array is called $res.

Now, i need to put a value from $res into another array for loading to the DB (magento SOAP API). But when i do this i do not get a string value i wxpect, instead i get an the first array inside the second.

Here is the problem line:

$fieldDateData = array('rts_date'=>$res[0]->BackInStockDate1);

I've tried a few different things, none have worked. I thought it would be simply enough to do this:

$data = $res[0]->BackInStockDate1;
$fieldDateData = array('rts_date'=>$data);

But sadly not, i'm unsure as to why?

Thanks,

EDIT:

This is an example of the output

Array
(
    [rts_date] => SimpleXMLElement Object
        (
            [0] => 28/06/13
        )

)
bulldog5046
  • 197
  • 2
  • 11
  • You have not told why this is a problem for you. Normally that value is used as string when you use it in string context. So casting is not always necessary. However if casting is necessary for you (as your accepted answer suggests), then this is a duplicate. – hakre Jun 08 '13 at 19:30

2 Answers2

1

Try

$data = (string)$res[0]->BackInStockDate1;
$fieldDateData = array('rts_date'=>$data);
Fo.
  • 3,752
  • 7
  • 28
  • 44
1

You need to cast the value you are setting as a string:

$data = (string) $res[0]->BackInStockDate1;
$fieldDateData = array('rts_date'=>$data);
adear11
  • 935
  • 6
  • 11