SoFunction
Updated on 2025-03-10

php method to convert array values ​​into keys

This article describes the method of converting array values ​​into keys by php. Share it for your reference. The details are as follows:

function values2keys($arr, $value=1){
  $new = array();
  while (list($k,$v) = each($arr)){
    $v = trim($v);
    if ($v != ''){ 
      $new[$v] = $value;
    }
  }
  return $new;
}

I hope this article will be helpful to everyone's PHP programming.