I was X years old when I learned that PHP's array_push() does not return the new array, but rather the amount of elements in the array.

@derickr I’ve always wondered why folks use array_push() instead of $array[], other than the obvious logical treatment of an array as a stack, but getting back the number of elements points to another reason one might use it.

@ramsey In my case, it is because I needed to test the result of a function call within the Xdebug protocol :-). So no real use case.

@derickr Still, there have been many times I’ve reviewed code and asked this question, only to get the response, “I didn’t know I could add elements to the array with $array[].”

Sign in to participate in the conversation
PHP Community on Mastodon

Open source. Open community. We are dedicated to building and enriching the PHP community.