function example()
{
foreach ($choices as $key => $choice) { # \__ both should run parallel
foreach ($vtitles as $keystwo => $vtitle) { # /
$options .= '<option value="'. check_plain($key) .'" title="' . $vtitle . '"' . $selected
.'>'. check_plain($choice) .'</option>';
} // end of vtitle
} // end of choice
return $options;
}
Answers to some of the below questions and what I am trying to achieve.
- Array
$choices
is not numerically indexed. - Array
$vtitle
is numerically indexed. - They won't be shorter than each other as I have code which will take care of this before this code runs.
- I am trying to return
$options
variable. The issue is that$choices[0]
and$vtitle[0]
should be used only once. Hope I was able to express my problem. - I do not want to go through the
$vtitles
array once for each value in$choices
.
@hakre: thanks I have nearly solved it with your help.
I am getting an error for variable $vtitle
:
InvalidArgumentException: Passed variable is not an array or object, using empty array
instead in ArrayIterator->__construct() (line 35 of /home/vishal/Dropbox/sites/chatter/sites
/all/themes/kt_vusers/template.php).
I am sure its an array this is the output using print_r
Array ( [0] => vishalkh [1] => newandold )
What might be going wrong ?
The below worked for me , thank you hakre
while
(
(list($key1, $value1) = each($array1))
&& (list($key2, $value2) = each($array2))
)
{
printf("%s => %s, %s => %s \n", $key1, $value1, $key2, $value2);
}