Creating an array from three arrays with unequal but related elements

Am trying to replace array in this manner using php

$a = array(1,2,3);

$b = array(3,4,5);

$c = array(3,3,4,4,5,5);

What I want to achieve is this

$c = array(1,1,2,2,3,3);

Note: They all have the same key. And $a corresponds to $b where $b in another table is occuring multiple times as seen in $c.

Please I need quick response as am in the midst of something.

where? i don’t see any code. and the relations don’t make sense to me.

So the third array shows how many times the elements in the second array are repeated and you want to form an array that repeats the elements in the first array the same number of times?

yes. Though have done it

Can you post your code so that we can see how you did it?

function getReplaced($a, $b, $c) {
	$d = $c;
	foreach($c as $i=>$x) {
		if( in_array($d[$i], $b) ) {
			$d[$i] = $a[array_search($d[$i], $b)];
	return $d;

devil’s mother of variable names… who should maintain this five years in the future?

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.