A
A
androids2018-11-07 16:52:38
PHP
androids, 2018-11-07 16:52:38

How to pass a parameter in PHP?

There is a method in the api.php file that looks like this:

public function cnb_form($params)
{

$language = 'ru';
if (isset($params['language']) && $params['language'] == 'en') {
$language = 'en';
}

$params = $this->cnb_params($params);
$data = base64_encode( json_encode($params) );
$signature = $this->cnb_signature($params);

return sprintf('
<form method="POST" action="%s" accept-charset="utf-8">
<input type="text" name="price">
%s
%s
<input type="submit">
</form>
',
$this->_checkout_url,
sprintf('<input type="hidden" name="%s" value="%s" />', 'data', $data),
sprintf('<input type="hidden" name="%s" value="%s" />', 'signature', $signature),
$language
);
}

I need to pass the value of the amount (price) to another function (located in my.php file)
function addbalance(){
require("api.php");

$micro = sprintf("%06d",(microtime(true) - floor(microtime(true))) * 1000000);
$number = date("YmdHis");
$order_id = $number.$micro;

$merchant_id= "****";
$signature="****";

$desc = $_GET[‘desc’]; 
$order_id = $_GET[‘order_id’]; 
$price = $_POST['price']; 
$liqpay = new LiqPay($merchant_id, $signature, $price);
$html = $liqpay->cnb_form(array(
'version' => '3',
'amount' => $price,
'currency' => 'UAH', 
'description' => "Пополнение баланса", 
'order_id' => $order_id
));

echo $html;
}

The above construction does not work. New to OOP. And after much deliberation, I got completely confused. Thank you in advance for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rombick, 2018-11-07
@rombick

In the function declaration, in parentheses, specify the necessary variables.
For example:

function addbalance($price){
    необходимые действия.
}
addBalance(800); // 800 это передаваемая цена, можешь передать переменную.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question