1

I am just having one of those days. How can query the "116" in this array and set it to a variable?

Array
( 
    [pa_vendor] => Array 
    ( 
         [terms] => Array 
              ( 
                  [0] => 116 
              )
         [query_type] => and
    )
)
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
  • You reference it like this: `$value = $array['key']` - you have a multi level array and will need to add multiple keys though – JimL Apr 28 '16 at 17:48

3 Answers3

0

Try this

let the array is $arr.

echo $variable_store = $arr['pa_vendor']['terms'][0]; //116
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
0

$NewVariableName = $terms[0];

See:

http://www.homeandlearn.co.uk/php/php6p3.html

http://php.net/manual/en/function.array-keys.php

Atrix
  • 299
  • 2
  • 6
0

Your array splits like this

Your array has one element, this is the element with 'pa_vendor' as index. It can be accessed by using

 $arr['pa_vendor']

$arr['pa_vendor'] is een array with two elements first element has index 'terms' and is an array second element has index 'query_type' and is a string. These can be accessed by using

$arr['pa_vendor']['terms']

and

$arr['pa_vendor']['query_type']

$arr['pa_vendor']['terms'] is an array with one element this element has index '0' and is a number this element can be accessed by using

$arr['pa_vendor']['terms'][0]
RST
  • 3,899
  • 2
  • 20
  • 33