Is it possible to apply compact() to the elements of an array? For instance, instead of Code: $name = 'John'; $city = 'Denver'; $state = 'Colorado'; print_r(compact('name', 'city', 'state')); Something like Code: $arr['name'] = 'John'; $arr['city'] = 'Denver'; $arr['state'] = 'Colorado'; print_r(compact(...on each key of $arr...)); 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(). Kadence is offline Reply With Quote
//This what you mean $element = array(); $element['Name'] = 'OOP'; $element['Age'] = 20; $element['colour'] = 'white'; foreach($element as $key => $val){ print_r( compact( $key , $val ) ); } PHP: lol cant really userstand what you mean but thought id have a shot at it.