If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
PHP में array_combine() method , दो Indexed Array Elements को आपस में key => value pair में Associate करके एक नया Associative Array बनाता है।
इस method में पहले pass किये गए Array values को keys बनता है , और बाद में pass किये गए Array की values को उन keys के साथ Associate करता है।
array_combine ( array $keys , array $values );
array $keys | required : यह वो Array variable है जिसकी values को key बनाया जाता है।
array $values | required : इस Array variable की values को as a value use किया जाएगा।
Return Value : एक नया Associative Array मिलता है। अगर दोनों Arrays की value same नहीं हुई तो false return होता है।
File : php_array_combine.php
<?php
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);
print_r($c);
?>
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
) अगर pass किये गए Array में key same हुई तो value हमेशा बाद वाली key के साथ ही associate होती है।
For Example :
print_r(
array_combine(
['name', 'name', 'age'],
['Rahul Kumar', 'Rahul Rajput', 23]
)
);
Ouput
Array
(
[name] => Rahul Rajput
[age] => 23
)