Hi. I have a function A in which I created an array with values. I have a function B in which I want to access array values from the function A, and display them in a dropdown list.
I have went through the documentation of Variable scope, passing variables and arrays as function arguments, declaration of global variables. Can’t get around it and would love some more insight and guidance.
Here is my latest attempt (unsuccessful )
Function A:
function cfwc_create_custom_field() {
$args_select_stone = array(
'options' => array('Stone' => 'Amethyst', 'Agate', 'Pink quartz', 'Bismuth', 'Bloodstone', 'Buddstone',
'Calcite', 'Dolomite', 'Fluorite', 'Hematite', 'Iolite', 'Jasper'),
);
}
Function B:
function cfwc_display_custom_field(&$args_select_stone) {
...
'echo html'
foreach($args_select_stone['options']['Stone'] as $stones) {
'echo html'
echo $stones;
...
}
I know that you cannot just access variables outside of the function scope, but I also realize that it is possible, I am just not able to do it myself (yet). Help appreciated