Prefixing array keys with a string (:) in PHP

后端 未结 4 565
臣服心动
臣服心动 2021-01-18 10:56

Quick one; I know a solution, but I\'m looking for something more elegant if it exists.

I\'m using PDO for prepeared statements:

$sql = \"INSERT INTO         


        
4条回答
  •  礼貌的吻别
    2021-01-18 11:46

    It has already been answered but this is what I came up with anyway.

    $arr = array('foo'=>1,'bar'=>2);
    
    $arr = array_flip($arr);
    
    array_walk($arr,create_function('&$v,$k', '$v = ":$v";'));
    
    $arr = array_flip($arr);
    
    print_r($arr);
    

提交回复
热议问题