B
B
BonBon Slick2016-10-15 17:11:18
PHP
BonBon Slick, 2016-10-15 17:11:18

Why doesn't it swap array elements?

$arr = ['10','12','15','19','20'];
  $min =  min( $arr );
  $max = max( $arr );
 
 	$min_index =  intval(array_search($min, $arr));
  $max_index =  intval(array_search($max, $arr));
 
 	$arr[ $max_index ] = $min ;
 	$arr[ $min_index ] = $max;

$max_index will output the desired index, however, writing $arr[ $max_index ] = $min ; for some reason does not replace the numbers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2016-10-15
@BonBonSlick

эмм...
ideone.com/BU56Yb кагбе все верно.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question