1

I'm trying to store an array ($temp) into the $data array, where key is prices.

$data['prices'] = $temp;

However, PHP converts the array into string instead and is throwing me and error.
Notice: Array to string conversion

Is $data = array('prices' => $temp); the only solution?

edit:
I found my mistake. Yes, $data was used previously as a string that's why PHP is converting the input into string.
Problem 2, doing a print_r on $data['prices'] = $xml->result->Prices->Price, shows only 1 set of array. But I am able to retrive 2 sets of result by doing a foreach loop on $data['prices']. Why is that so?

Content of $temp http://pastebin.com/ZrmnKUPB

Let me be more clear..
The full xml object I'm trying to extract information from: http://pastebin.com/AuMJiyrw
I'm only interested in the price array (Price_strCode and Price_strDescription) and store them in $data['prices']. End result something like this:

Array(
    [0] => (
        [Price_strCode] => 0001
        [Price_strDescription] => Gold
    )
    [1] => (
        [Price_strCode] => 0002
        [Price_strDescription] => Silver
    )
)
1
  • What line is giving you array-to-string-conversion? What are the contents of data and temp? Commented Aug 8, 2011 at 3:12

2 Answers 2

2

Unless you are doing some other array to string conversion elsewhere, the array is actually being stored as another array.

$data['prices'] will be an array, which can be accessed as $data['prices']['key'].

Sign up to request clarification or add additional context in comments.

Comments

0

This is not possible, I have been doing this always and it works fine. You must be doing something else somewhere which is causing your array to convert to strong. share your code here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.