After recently answering a couple of questions here on SO that involved utilizing PHP's list
function, I wondered, "how in the world does that function actually work under the hood?". I was thinking about something like using func_get_args()
and then iterating through the argument list, and that's all nice and peachy, but then how in the world does the assignment part work?
list(...) = array($x, $y, $z);
isn't this ^ evaluated first?
So to be precise, my question is how is the list
function able to create scoped variables which get assigned to the not-yet evaluated array?
The array_flip() function is used to exchange the keys with their associated values in an array. The function returns an array in flip order, i.e. keys from array become values and values from array become keys. Note: The values of the array need to be valid keys, i.e. they need to be either integer or string.
The closest PHP likeness to the ArrayList class from Java is the ArrayObject class. The method names are different, but the functionality between the two is fairly close. but it doesn't have contains method.
Description ¶array_values() returns all the values from the array and indexes the array numerically.
list
is a language construct, not a function. It does not play by the rules of normal functions, it's more akin to an if
or for
(or array()
, as the manual states), hard-coded into the PHP core.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With