Is it possible to apply compact() to the elements of an array? For instance, instead of
Something likeCode:$name = 'John'; $city = 'Denver'; $state = 'Colorado'; print_r(compact('name', 'city', 'state'));
I was thinking of iterating over $arr with a foreach() loop and compact()ing each element individually, but I don't know how to pass the element keys as varnames that make sense to compact().Code:$arr['name'] = 'John'; $arr['city'] = 'Denver'; $arr['state'] = 'Colorado'; print_r(compact(...on each key of $arr...));





Just something I was curious about.

Bookmarks