Home >> PHP >> compact() function in PHP

compact() function in PHP

The compact() function used for generate an array from variables and their values.

Syntax

compact(variable1,variable2,variable3...)

Example

$a = "Ram";
$b = "Shyam";
$c= "Ghanshyam";

$result = compact("a", "b", "c");

print_r($result);

Output

Array ( [a] => Ram [b] => Shyam [c] => Ghanshyam )

Post Your Comment

Next Questions
count() function
current() function
each() function
end() function
extract() function
in_array() function
key() function
krsort() function
ksort() function
list() function
natcasesort() function
natsort() function
pos() function
prev() function
range() function
reset() function
rsort() function
shuffle() function
sizeof() function
sort() function
uasort() function
uksort() function
usort() function
What is the difference between array_combine() and array_merge()
What are the differences between array_diff(), array_diff_assoc() and array_diff_key()

Copyright ©2022 coderraj.com. All Rights Reserved.