0

I have two array like these.

array("a","b","c");

array("1","2","3");

I have to add those items like that way.

$c=array("a"=>"1","b"=>"2","c"=>"3");

how can i retrieve each inner array by this way.

echo $c[0];

0

3 Answers 3

4

Use array_combine()

Creates an array by using the values from the keys array as keys and the values from the values array as the corresponding values.

<?php
$a = array("a","b","c");
$b = array("1","2","3");
$c = array_combine($a, $b);

print_r($c);
?>

The above example will output:

Array
(
    [a] => 1
    [b] => 2
    [c] => 3
)
Sign up to request clarification or add additional context in comments.

Comments

0
$new_array = $array;
array_unshift($new_array, $value1);
array_push($new_array, $value2);

Comments

0

Use array_merge method for combining two arrays . Array_merge($arr1'$arr2);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.