Home arrow PHP arrow PHP array_combine Function

PHP array_combine Function

In this programming tutorial you will learn how to work with the PHP array_combine function, which allows you to combine arrays into a single array.

By: TheloniusFunk
Rating: starstarstarstarstar / 0
April 09, 2012

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

This function takes two existing arrays and combines them into one array. Note that the first array must contain the key values that you want, while the second array must contain the values.

Syntax:

array_combine(name of the first array(keys), name of the second array(values))

Programming Samples and Usage:

 

<?php

$test = array ("a","b","c");
$test2 = array ("Superman", "Batman", "Sandman");

print_r(array_combine($test,$test2));

?>

 

The above code takes the values in the array $test (representing the keys) and combines them with the values in $test2 (representing the values).

The result is:

 

array (
[a] => Superman [b] => Batman [c] => Sandman
)


 
 
>>> More PHP Articles          >>> More By TheloniusFunk
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: