Merging two arrays without changing key values by keeping array php -


i have tree arrays in php shown in code

<?php //old array $oldarray = array(0 => 11, 1 => 18, 2 => 29, 3 => 35, 4 => 40);  // held values $hold = array( 1 => 18, 3 => 35);  // new random generated array  $newvalues = array( 0 => 27, 1 => 31, 2 => 38);   //i need keep keys (order, index) of $hold values  newarraymergedpushed = array(0 => 27, 1 => 18, 2 => 31, 3 => 35, 4 => 38); ?> 

i need keep order of $hold array in same order,index in $oldarray. function can use in php following output obtained without changing key values?

if i'm guessing want correctly, it's better operate directly on array want change rather creating range first , trying mix them in.

hold indexes want keep in lookup table, loop on table , replace key=>values aren't held.

$oldarray = array(0 => 11, 1 => 18, 2 => 29, 3 => 35, 4 => 40); $hold = array( 1 => true, 3 => true); for( $i = 0; $i < count($oldarray); $i ++ ) {   if( !isset( $hold[$i] ) ) {     $oldarray[$i] = mt_rand(0,100); // or whatever generate random numbers   } } 

that way won't have merging @ all.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -