how to flip flip STRING and decimal/ float values in array PHP? -


i trying make app allow me rank , sort decimal number according it's value , array_flip function can't flip string , decimal number ,

 <?php  $myarray = array(1,0.334,-0.334,-1);  //create copy , sort $myarray_copy = $myarray; rsort($myarray_copy); //reverses key , values $myarray_copy = array_flip($myarray_copy); //create result using keys sorted values + 1 foreach($myarray $val)     $myarray2[] = ($myarray_copy[$val]+1); //print final array print_r($myarray2); print_r($myarray);   ?> 

and there warning array_flip

warning: array_flip() [function.array-flip]: can flip string , integer values! in c:\xampp\htdocs\ranking.php on line 9

, guys know how deal these ? there solution ?

after sort use array_walk convert each item decimal string ---

function test_alter(&$item1, $key) {     $item1 = (string)$item1; } array_walk($fruits, 'test_alter', 'fruit'); 

and flip it. hope helps.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -