PHP Array in Select return

I have a query that has an array in the return.  I'm not sure how to get at the items in the array and create variables from them.
My Query:
<?php
$open_order_id = $this->db->select('*')
					->where('member_id', $member_id)
					->where('status', 'open')
					->get('exp_cartthrob_subscriptions');
						
				$open_orders = $open_order_id->result_array();
				
				$open_order_id->free_result();
			//echo '<pre>';
			//var_dump($open_order_id);
			//echo '</pre>';
				
				foreach($open_orders as $row)	{

			$extra = _unserialize($row['serialized_item'], TRUE);
			
			// $keep_extra seems to be undefined, I'm going to set it to false up above so it writes out the row[$keys]
			if ($keep_extra)
			{
				$row['extra'] = $extra;
			}
			else
			{
				foreach ($extra as $key => $value)
				{
					if ( ! isset($row[$key]))
					{
						$row[$key] = $value;
					}
				}
				unset($row['serialized_item']);			
			}
echo '<pre>';
var_dump($extra);
echo '</pre>';
}
?>

Open in new window


From The var_dump I get the following:
array(17) {
  ["row_id"]=>
  int(0)
  ["quantity"]=>
  float(1)
  ["product_id"]=>
  string(2) "29"
  ["site_id"]=>
  string(1) "1"
  ["shipping"]=>
  int(0)
  ["weight"]=>
  string(0) ""
  ["price"]=>
  float(317)
  ["no_tax"]=>
  bool(true)
  ["no_shipping"]=>
  bool(true)
  ["item_options"]=>
  array(45) {
    ["insured_first_name"]=>
    string(10) "First Name"
    ["insured_last_name"]=>
    string(9) "Last Name"
    ["location_address"]=>
    string(16) "123 Test Address"
    ["location_city"]=>
    string(9) "Test City"
    ["location_state"]=>
    string(2) "AR"
    ["location_zip"]=>
    string(5) "65401"
    ["location_phone"]=>

Open in new window


I want to know how I get at the items_options array /     ["insured_first_name"]=>
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
Do you mean this?

echo $extra['items_options']["insured_first_name"];

Open in new window

gplanaCommented:
In php you have foreach for getting elements of an array one by one:
http://php.net/manual/en/control-structures.foreach.php

I think you should just use this:

$items_options = $row['item_options'];
foreach ($items_options as $item_option){
      foreach ($item_option as $key => $value)
      {
            if ( ! isset($row[$key]))
            {
                  $myoptions[$key] = $value;
            }
      }
}

Is that what you want?
rgranlundAuthor Commented:
I wrote it like this but this does not work.  Maybe you can elaborate a little more?
<?php
$open_order_id = $this->db->select('*')
					->where('member_id', $member_id)
					->where('status', 'open')
					->get('exp_cartthrob_subscriptions');
						
				$open_orders = $open_order_id->result_array();
				
				$open_order_id->free_result();
			//echo '<pre>';
			//var_dump($open_order_id);
			//echo '</pre>';
				
			foreach($open_orders as $row)	{

			$extra = _unserialize($row['serialized_item'], TRUE);
			
			// $keep_extra seems to be undefined, I'm going to set it to false up above so it writes out the row[$keys]
			if ($keep_extra)
			{
				$row['extra'] = $extra;
			}
			else
			{
				foreach ($extra as $key => $value)
				{
					if ( ! isset($row[$key]))
					{
						$row[$key] = $value;
					}
				}
				unset($row['serialized_item']);
			$id = $extra['items_options']["insured_first_name"];				
			}
			
			echo '<pre>';
			var_dump($id);
			echo '</pre>';		
	
				}

Open in new window

Marco GasiFreelancerCommented:
I was going crazy and even a second I would have poted a question here at Experts-Exchange ;-)
I was just a typo: I wrote items_options instead of item_options!

$id = $extra['item_options']["insured_first_name"];

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.