Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

This question already has an answer here:

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
        )

)
share|improve this question

marked as duplicate by hakre, Jocelyn, tereško, Achrome, Graviton Jun 15 '13 at 5:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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 8 '13 at 19:30

2 Answers 2

up vote 1 down vote accepted

Try

$data = (string)$res[0]->BackInStockDate1;
$fieldDateData = array('rts_date'=>$data);
share|improve this answer
1  
It might be worth pointing OP to php.net/manual/en/… – Anthony Sterling Jun 8 '13 at 16:25
    
Thank you both, very helpful answers! – bulldog5046 Jun 8 '13 at 16:30

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

$data = (string) $res[0]->BackInStockDate1;
$fieldDateData = array('rts_date'=>$data);
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.