Soumya Mohanan
Soumya Mohanan

Reputation: 316

How to extract the result form array

I need to extract the result from below array

 Array ( [model_type] =>
        Array ( [label] => Model Type
                [value] => Inspiron 
                [code] => model_type )
         [model_version] => 
        Array ( [label] => Model Version
                [value] => 100L
                [code] => model_version )
        [color] => 
         Array ( [label] => Color 
                 [value] => Black
                 [code] => color )
    )  

How can i get the result Model type as Inspiron and color as black

Please help , Any help will be appreciated.

Upvotes: 0

Views: 97

Answers (3)

Cyril F
Cyril F

Reputation: 1882

You could simply do the following :

$model = $result['model_type']['value'];

$color = $result['color']['value'];

and then simply echo both values

echo $model . " is " . $color;

Upvotes: 0

Coder anonymous
Coder anonymous

Reputation: 927

You can do it like this:

foreach($results  as $key => $value)
{ 
   if($key == 'model_type') 
      echo $value['value'];

    if($key == 'model_version')
     echo $value['color'];
}

Upvotes: 0

Daedalus
Daedalus

Reputation: 7722

Given this content, this is a rather simple answer. Simply type $yourvariable['model_type']['value']; and $yourvariable['color']['value'];. This will get you both of the vailes you are after, assuming your variable is called $yourvariable. I would suggest you give the manual a read when you get the chance.

Upvotes: 1

Related Questions