Created
March 17, 2012 16:30
-
-
Save varemenos/2061835 to your computer and use it in GitHub Desktop.
PHP - Compact Variables into an Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = 'James'; | |
$surname = 'Pond'; | |
$job = 'Failure'; | |
$temp = array('name', 'surname'); | |
$result1 = compact($temp, 'job'); | |
$result2 = compact($temp[0], $temp[1], 'job'); | |
var_dump($result1); | |
// RESULTS | |
/* | |
// same result for both versions | |
array | |
'name' => string 'James' (length=5) | |
'surname' => string 'Pond' (length=4) | |
'job' => string 'Failure' (length=7) | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment