kalster Posted March 8, 2015 Share Posted March 8, 2015 using php, how to delete values from an array and place those values in another array.Is it possible to take an array like this...Array ( [0] => Array ( [0] => var1 [1] => 1 [2] => var2 [3] => 2 [4] => 3 ) )and make two arrays like this...Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) )Array ( [0] => Array ( [0] => var1 [1] => var2 ) )The word "var" inside of the array does not change value but numbers can change values. Link to comment https://forums.phpfreaks.com/topic/295160-delete-values-from-an-array-and-place-those-values-in-another-array/ Share on other sites More sharing options...
Barand Posted March 8, 2015 Share Posted March 8, 2015 If var1 and var2 never change then you can pre-construct that array then create the third array from the difference $arr = array ( array('var1', 1, 'var2', 2, 3) ); $result[0] = array ('var1', 'var2'); //pre-construct $result[1] = array_values(array_diff($arr[0], $result[0])); echo '<pre>',print_r($result, true),'</pre>'; gives Array ( [0] => Array ( [0] => var1 [1] => var2 ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) Link to comment https://forums.phpfreaks.com/topic/295160-delete-values-from-an-array-and-place-those-values-in-another-array/#findComment-1507859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.