Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: value returned instead change the value of the variable Date: Fri, 16 Oct 2020 20:51:12 +0200 Lines: 64 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net Xgdk4rNgkmbrLeadqmg48wRd8z15kuXdQmyBqA/5HBnZD2QQA/ Cancel-Lock: sha1:awK9Ed+p1keu2HzoBU0fLjc/3/E= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 In-Reply-To: Content-Language: en-US-large Xref: csiph.com comp.lang.php:18389 On 16/10/2020 13.23, alex wrote: > // DESIGN 1 > echo "It doesn't work (return 1 vs array), but I like 'DESIGN 1' "; > $arr = [1, 2]; > print_r( >     array_shift($arr) > ); > > Output: > > It doesn't work (return 1 vs array), but I like 'DESIGN 1': 1 > If you look at your original array, the cell 0 has an integer, so the return type will be int. See https://www.php.net/array_shift it say's: Return Values Returns the shifted value, or NULL if array is empty or is not an array. If you prompt want an array, either you make it to one afterwards or store the values as single cell arrays in the main array Alt 1: array(array_shit($arr)); Alt 2: $arr = [[1],[2]]; > // DESIGN 2 > echo "It works, but I don't like 'DESIGN 2': "; > $arr = [1, 2]; > array_shift($arr); > print_r( >     $arr > ); > > Output: > > It works, but I don't like 'DESIGN 2': Array > ( >     [0] => 2 > ) Sure we compare apples and oranges, the $arr will be an array even if you shift out the last value from it. try this: $arr = [1, 2]; array_shift($arr); print_r($arr); array_shift($arr); print_r($arr); echo "This will confuse you even more\n"; print_r(array_shift($arr)); -- //Aho