Reputation: 1379
I have variable:
$default['text']="This is default text";
and $other_text['text']="This is other text";
I would like to choose one of them in function:
function insertText($param){
if(isset($other_text[$param]))
echo($other_text[$param]); (*)
else
echo($default[$param]); (**)
}
if instead of lines (*) and (**) I write something like: echo("other_text");
and echo("default_text");
I always receive second option. That's why I assume there is something wrong with $var[$param]
construction. How should that look like?
Upvotes: 0
Views: 16
Reputation: 4121
If $default['text']="This is default text";
and $other_text['text']="This is other text";
are defined outside the function body, then you should declare them as global inside your function:
function insertText($param){
global $default, $other_text;
if(isset($other_text[$param]))
echo($other_text[$param]); (*)
else
echo($default[$param]); (**)
}
If you don't do that, then the check isset($other_text[$param])
will always return false
.
Upvotes: 1