php example code : array_combine function in php - combine two arrays to an array
array-combine-example-in-php.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>php example code : array_combine function in php - combine two arrays to an array</title>
</head>
<body>
<h3>php example code : array_combine function in php - combine two arrays to an array</h3>
<?php
/*
--------------------------------------------------------
let us make an array, keys for the final array
--------------------------------------------------------
*/
$myArrayKeys = array('key1', 'key2', 'key3');
/*
--------------------------------------------------------
let us make another array, values for the final array
--------------------------------------------------------
*/
$myArrayValues = array('value1', 'value2', 'value3');
/*
--------------------------------------------------------------------
combine the two arrays using array_combine to make a single array
--------------------------------------------------------------------
*/
$finalArray = array_combine($myArrayKeys, $myArrayValues);
echo "<p style='background:#ccc; color:red;'>Output of final array using array_combine function</p>";
echo "<pre>";
print_r($finalArray);
echo "</pre>";
echo "<pre>";
var_dump($finalArray);
echo "</pre>";
?>
</body>
</html>

No comments:
Post a Comment
leave your comments here..