0

I'm new at PHP so forgive me if this question has been asked. How do you combine two PHP arrays into one? This is the code I'm using that needs to be combined:

<?php $duplicates[] = get_the_ID(); ?>
<?php $images = get_attached_media( 'image', $post->ID );?>

Thanks for the help.

0

3 Answers 3

1

If all you need to do is merge two arrays into one, this should do the trick:

$new_array = array_merge($duplicates, $images);
Sign up to request clarification or add additional context in comments.

Comments

0

Array Combine Procedure

Code:

<?php
$a1=array("red","green");
$a2=array("blue","yellow");
print_r(array_merge($a1,$a2));
?> 

Output:

Array ( [0] => red [1] => green [2] => blue [3] => yellow ) 

1 Comment

In as per your request you have to do like this: $resultant_array = array_merge($duplicates,$images). This will result in an single array as per my example. :)
0

PHP function 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.

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.