PHP返回空值

时间:2019-05-17 01:51:56

标签: php

为什么此代码返回null?

public function getPrice($crawler){
        $price = '';

            $crawler->filter('#j-sku-price')->each(
            function ($node) {
            $price = $node->text();
            });

return $price;

如果我这样写

public function getPrice($crawler){
        $price = '';

            $crawler->filter('#j-sku-price')->each(
            function ($node) {
            $price = $node->text();
                print($price);
            });

有效。但我想最后返回$ price。

1 个答案:

答案 0 :(得分:0)

您将在$ price_array中获得价格

    cc_binary {
    name: "sh_vendor",
    defaults: ["sh-defaults"],
    stem: "sh",
    vendor: true,
    cflags: [
        // Additional flags for vendor variant
        "-UMKSH_DEFAULT_PROFILEDIR",
        "-UMKSHRC_PATH",
        "-UMKSH_DEFAULT_EXECSHELL",
        "-DMKSH_DEFAULT_PROFILEDIR=\"/vendor/etc\"",
        "-DMKSHRC_PATH=\"/vendor/etc/mkshrc\"",
        "-DMKSH_DEFAULT_EXECSHELL=\"/vendor/bin/sh\"",
        "-DMKSH_DEFPATH_OVERRIDE=\"/vendor/bin:/vendor/xbin\"",
    ],  
}