简体   繁体   中英

How to dynamically change variable in php

I have a token for a specific ID number which is 494

$url = api.pipedrive.com/v1/deals/494/products?start=0&api_token=7ecb71622dadd2faae2732bfe73b09381150c967;

I want to change the number 494 to any number.

I've made an illogical code to begin with.

Any guide on how to do this?

$url = "https://api.pipedrive.com/v1/deals/";
$id = 494;
$api = "/products?start=0&api_token=7ecb71622dadd2faae2732bfe73b09381150c967";

$response = file_get_contents($url+$id+$api);
echo $response;

$object = json_decode($response, true);

I got the errorL

Warning: file_get_contents(494): failed to open stream: No such file or directory

You are using '+' operator to concatenate. Which sums two variable. You need to use concatenation operator ('.') not '+'

$url = $url.$id.$api;

In PHP, . is used for string concatenation. Also you can use the .= to append a string to a string variable. Example:

$str = "Hello";
$str2 = $str . "Anthea"; // $str2 = "Hello Anthea"

Or

$str = "Hello";
$str .= "Anthea"; // $str = "Hello Anthea"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM