Home  >  Q&A  >  body text

Extract variables from php file from function in another file

I have a php file in the root directory and I want to retrieve a variable from a function in another php file. I need it for SQL queries.

My php file is in the root directory

<?php
    require dirname(__FILE__) . '/config/config.inc.php';
    require 'modules/pricefrom/pricefrom.php';

    $lowestPrice = Db::getInstance()->getValue('
            SELECT MIN(`price`)
            FROM `' . _DB_PREFIX_ . 'product_attribute`
            WHERE `id_product` = ' . (int)$id_product
    );

I need to get $id_product from another file that is required and is inside a function and uses the parameters of that function.

<?php
    ...
    public function hookDisplayPriceBlock($param) {
            $id_product = $param['id_product'];
            $id_product_attribute = $param['id_product_attribute'];
            $product = new Product();
            ...

I know there is an easy way to do this, but I've been searching for hours and can't find it, can you guys help me?

P粉198670603P粉198670603431 days ago537

reply all(1)I'll reply

  • P粉256487077

    P粉2564870772023-09-08 11:44:50

    Use

    in the root directory
    require_once('<path to file2.php>');
    $id_product = hookDisplayPriceBlock(<params>);
    .....

    File 2

    public function hookDisplayPriceBlock($param) {
        ...
        return $id_product;
    }

    reply
    0
  • Cancelreply