Php返回值错,任何想法为什么?

时间:2016-05-04 12:29:12

标签: php return

在发帖之前,我想说,我对PHP很新。

它返回“value wrong”,这是我创建的一个echo:

$fields = array(  "amount"=>("5"),
                  "selected_customfields"=>("26656"),
                  "pageno"=>("0"),
                  "show_active_only"=>("1"),
                  "api_group"=>("//i removed this for here"),
                  "api_secret"=>("//i removed this for here"));

// Make the POST request using Curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);   
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

// Decode and display the output
$api_output =  curl_exec($ch);
$json_output = json_decode($api_output);
$output = $json_output?$json_output:$api_output;

// Clean up
curl_close($ch);

echo '<pre>';
var_dump($output);
echo '</pre>';


$output_filtered = array();

    foreach ($output as &$value) {
        echo '<pre>';
        $type = $value->cf_value_26656;

    if($type == "Opzet & webdevelopment (Eenmalig)") {
        var_dump($value);   
    } else {
        echo 'value wrong';
    }
    //var_dump();

        echo '</pre>';
        echo '==================================';
    }

cf_value_26656是对的,因为我对此很新。有人可能会很快看到错误..

我在此更新了更多代码,请原谅我之前没有上传。

问候,

凯文

1 个答案:

答案 0 :(得分:0)

由于您的var_dump输出

  

string(37)“Opzet&amp; webdevelopment(Eenmalig)”

我们可以看到有4个缺少的字符(该字符串中有33个字符)。由于您在浏览器中进行调试,因此输出不是实际输出。 &实际上是&amp;,呈现为&amp;说明了4个丢失的字符。因此,要么修改对实体的检查,要么将实体解码为其角色。

if($type == "Opzet &amp; webdevelopment (Eenmalig)") {

if(html_entity_decode($type) == "Opzet & webdevelopment (Eenmalig)") {