For example, i have 2 arrays,
$array_1 = array('100','250','300','50');
$array_2 = array('a','b','c','d');
next step : i'll sort array 1 and pass 2 arrays into a function, for example the function will return values greater than 100 .
Note: Sorting based on the value is important.(descending order).
Like: array which we are passing
rsort($array_1);
$return = parse($array_1,$array_2);
echo "<pre>";
print_r($return);
function parse(array $arr1,array $arr2){
$retArr1 = array();
$retArr2 = array();
foreach($arr1 as $k=>$value){
if($value > 100){
$retArr1[] = $value;
$retArr2[] = $arr2[$k];
}
}
return array($retArr1,$retArr2);
}
Output is coming like
Array
(
[0] => Array
(
[0] => 300
[1] => 250
)
[1] => Array
(
[0] => a
[1] => b
)
)
But i want like
Array
(
[0] => Array
(
[0] => 300
[1] => 250
)
[1] => Array
(
[0] => c
[1] => b
)
)
$retArr1[] = $value; $retArr2[] = $arr2[$k];(don't forget to initalize these empty arrays before the loop) and at the end return array($retArr1,$retArr2);$array_1 = rsort(array('100','250','300','50'));. Array sort functions operate by reference and you can only pass in variables.array_combineto map them together.rsort()the array that is returned from yourparse()function.