Printing a value from an array sometimes doesn't work

This is so strange. The first does not print anything, and if I do diewith random text attached to it, it prints id. Can someone explain?

It works:

        $product_ids = ProductToOption::groupBy('product_id')->get(['product_id']);

        foreach($product_ids as $product_id) {
            die("id: ".$product_id->product_id);
            array_push($filter_array, $product_id->product_id);
        }

But this is not so:

        $product_ids = ProductToOption::groupBy('product_id')->get(['product_id']);

        foreach($product_ids as $product_id) {
            die($product_id->product_id);
            array_push($filter_array, $product_id->product_id);
        }
+4
source share
1 answer

If the value passed to die () is int , it will not be printed, but used as the return code of the process executing the script - see http://php.net/manual/en/function.exit.php for more information .

int id: die() , id: 1.


exit():

, .

integer, , . 0 254, 255 PHP . 0 .

: PHP >= 4.2.0 , integer.

+8

Source: https://habr.com/ru/post/1619204/


All Articles