How to access function value in another function in PHP Classes

0 votes

How can I return a variable value from one function, pass it to another function in a class, and access it?

Code I have worked on:

<?php
class BioTool{
public function one(){
$lol =[2,3,5]; print_r($lol);
}
 public function two(){
     $newarr=$this->one(); //this only return the array but i can't access it, check below.
    print_r($newarr[0]); //not working
}
}

$biotool=new BioTool();
$biotool->two();

Can someone help me do this?

Jun 10 in PHP by narikkadan
• 10,840 points
6 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to import all classes from another namespace in PHP?

Hello @kartik, This is not possible in PHP. All ...READ MORE

answered Oct 20, 2020 in PHP by Niroj
• 82,720 points
2,440 views
0 votes
1 answer

How to access array returned by a function in php?

Hello @kartik, Since PHP 5.4 it's possible to ...READ MORE

answered Nov 10, 2020 in PHP by anonymous
• 82,720 points
350 views
0 votes
1 answer

How to access a global variable in a PHP function?

Hello @kartik, It is not working because you have to ...READ MORE

answered Nov 10, 2020 in PHP by Niroj
• 82,720 points
1,710 views
0 votes
1 answer

How to call function of one php file from another php file and pass parameters to it?

Hello @kartik, Include the first file into the ...READ MORE

answered Aug 27, 2020 in PHP by Niroj
• 82,720 points
12,470 views
0 votes
1 answer

How to delete element by value in array (not key) using php?

Hello @kartik, Using array_search() and unset, try the following: if (($key = ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,720 points
185 views
0 votes
1 answer

How to auto call function in php for every other function call?

Hii, Your best bet is the magic method __call, ...READ MORE

answered Oct 30, 2020 in PHP by Niroj
• 82,720 points
1,987 views
0 votes
1 answer

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required

Your mail.php on config you declare host ...READ MORE

answered Feb 16 in Others by Aditya
• 7,280 points
17 views
0 votes
0 answers

Laravel 5 – Clear Cache in Shared Hosting Server

php artisan cache:clear Is there any workaround to ...READ MORE

Jun 20 in PHP by Kithuzzz
• 320 points
5 views
0 votes
0 answers

NotFoundHttpException in RouteCollection.php line 161: in laravel 5

My CollectionController looks like this . <?php namespace App\Http\Controllers; use ...READ MORE

5 days ago in PHP by narikkadan
• 10,840 points
13 views
0 votes
0 answers

When to generate a new Application Key in Laravel?

As it automatically sets it for me ...READ MORE

4 days ago in PHP by narikkadan
• 10,840 points
5 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP