I need to access an array value but don't know all the values to call until I get them from a different array value. I'm not explaining this well so I will show some of the code below (This is from a drupal based website).

I want to access this value:

$variables[taxonomy][taxonomy_term_1083][title]

The problem is I don't know the term id (1083) until I have accessed this value:

$variables[field_journal_name][0][value]

I have tried creating a string that combines the term id with the rest of the array:

$termid = $variables[field_journal_name][0][value];
$taxname = 'variables[taxonomy][taxonomy_term_'.$termid.'][title]';

and then using the variable variable method:

$name = ${$taxname};

and many different variations of this but nothing seems to work.

Any ideas would be greatly appreciated.

Thanks - Dave.

Member Avatar for diafol

First of all, I think your array structure:

$variables[taxonomy][taxonomy_term_1083][title]

should be

$variables['taxonomy']['term']['1083']['title']

Anyway...

$taxname = 'variables[taxonomy][taxonomy_term_'.$termid.'][title]';

should be

$taxname = $variables['taxonomy']['taxonomy_term_'.$termid]['title'];
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.