Hello,

I need some help understanding how to display information from the following array and what this method of storage and array is called.

The information held in the database looks like this

{"option1":"1234","option2":"ABCD"}

How do I work with these values? I know how to get the array as a whole but how do I select option1 and the value on its own for example.

If I print the row it shows it as (extended being the field name in the DB)

Array
(
    [extended] => {"option1":"1234","option2":"ABCD"}
)

If someone could give some info on what I'm dealing with that would be great.

Thanks.

Hi,
Your dealing with an array ;)

Assuming your array is named $array all you would need to do it $array;

An example:

echo "Option 1: ".$array['option1']."<br />";
echo "Option 2: ".$array['option2']."<br />";

for($x=1; ( isset($array['option'.$x]) ); $x++)
{
  echo "Option ".$x.": ".$array['option'.$x]."<br />";
}

I hope this was your question ;)

Kieran :)

Unfortunately this hasn't worked. I know I'm dealing with an array but is there a specific term for how they have been stored? The actual values are stored in the mysql database as I posted, see the curly brackets.

{"option1":"1234","option2":"ABCD"}

Anyway the values are blank. What I did try was

$array = $value['extended'];
echo "Option 1: ".$array[token]."<br />";
echo "Option 2: ".$array['paypal']."<br />";

echoing $array shows the following so I don't understand why I cannot simply echo $array

Array
(
    [extended] => {"option1":"1234","option2":"ABCD"}
)

Hi,

Arrays are simple to use.

To get the following:

Array
(
    [extended] => {"option1":"1234","option2":"ABCD"}
)

You must be using print_r (am I right?);

So, assuming that the array is $array then you should use $array

echo "Option 1: ".$array['extended']['option1']."<br />";
echo "Option 2: ".$array['extended']['option2']."<br />";

for($x=1; ( isset($array['extended']['option'.$x]) ); $x++)
{
  echo "Option ".$x.": ".$array['extended']['option'.$x]."<br />";
}

kieran :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.