I have this snippet of a function inside a larger php class. I also get some simple data from my database which I have trouble getting into the array when fetching the variables.
$json = array();
$params = array(
'receiver_name' => $var,
'receiver_address1' => 'this works'
);
$ch = curl_init();
$query = http_build_query($params);
curl_setopt($ch, CURLOPT_URL, self::API_ENDPOINT . '/' . 'shipments/imported_shipment');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
$http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
$output = json_decode($output, true);
I've tried to assign the variable before the array starts, like this:
$var = $row['field_1'];
But it doesn't work when I try to insert this code. So I then tried:
$var2 = "'$var'"; // but quickly went back.
Since I thought it might have something to do with the quotes. I've tried several other ways of getting the variable to pass properly into the array. But when I don't know exactly what to read up on, I get stuck like this.
$params = array(
'receiver_name' => ".$var.", //this prints ..
'receiver_name' => "'.$var.'", //this prints '..'
Perhaps someone on here can tell me what terminology I should use for searching for more information related to this subject, as I seemingly have alot to read up on?
Update
I think everything should be cut out and simplified nicely now?
<?php
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
$p_name = $row['input_name'];
}
echo $p_name; // echo's correctly
class labels {
public function myFunction() {
$json = array();
$params = array(
'token' => $this->_token,
'name' => $p_name,
'hardcoded' => 'works fine'
);
}
}
echo $p_name; // echo's correctly
?>