0

If I have a function like this:

function getTotal() {
 $total = array("gcBalance" => 5, "gcTotal" => 10);
 return $total;
}

Is there a way I can call the function and get the gcBalance value out of the array without having to loop? Ideally it would work something like this, but it doesn't.

$balance = getTotal()[0];
echo $balance;

2 Answers 2

4

echo $balance['gcBalance'] should do it.

Sign up to request clarification or add additional context in comments.

1 Comment

Argh. I knew it was something simple; I've been staring at a huge chunk of code for way too long. Thanks.
2
$balance = getTotal();
echo $balance["gcBalance"];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.