Getting a variable value from a php class

In this function i am getting the value of “apartmentId”

function aptAction(){
$apartmentId = $user->getApartments()->get(0)->getId();

Now i have another function where i want to get this variable value, so i write like so —

$val = $this->aptAction()->apartmentId;

which is wrong i know.

If i write like so —

$val = $this->aptAction();

it will return a lot’s of value which i do not need, i need only a selected variable value, how i can do that. can anyone help me to fix this.

using $val = $this->aptAction();
isn’t going to work as currently, aptAction()
doesn’t actually return anything.

In order to use it in this way you need to return
a value out of it like this.

function aptAction(){

    return $user->getApartments()->get(0)->getId();

now when you call $val = $this->aptAction();
you will get the value you’re looking for.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Getting a variable value from a php class

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录