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, 2022 in PHP by narikkadan
• 63,420 points
835 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,880 points
4,673 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,880 points
682 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,880 points
6,736 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,880 points
24,365 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,880 points
1,602 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,880 points
5,959 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, 2022 in Others by Aditya
• 7,680 points
2,423 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, 2022 in PHP by Kithuzzz
• 38,010 points
376 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

Jun 24, 2022 in PHP by narikkadan
• 63,420 points
966 views
0 votes
0 answers

When to generate a new Application Key in Laravel?

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

Jun 25, 2022 in PHP by narikkadan
• 63,420 points
395 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP