Reputation: 1285
I have a function that returns an array but for some things I only need one of the values from that array. Here is the function:
function url_vars() {
$bank = strtolower($_GET['bank']);
$bank = str_replace(',', '', $bank);
$bank = str_replace(' ', '_', $bank);
$type = $_GET['type'];
$term = $_GET['term'];
return array(
bank => $bank,
type => $type,
term => $term,
term_yrs => $term / 12
);
}
I tried to target one value from another function with $bank = url_vars()['bank'];
but this seems to be incorrect as it is not working. How can I target a single value from this array? What is the correct way to do that?
Upvotes: 1
Views: 118
Reputation: 7930
In PHP 5.5 and higher, the url_vars()['bank']
syntax should work. However in lower version, you'll just have to assign the function return to a variable and then access the element from that.
$array = url_vars();
$bank = $array["bank"];
Upvotes: 3