Alternatives to Pass both Key and Value By Reference:

后端 未结 2 423
一生所求
一生所求 2021-01-18 03:13

Can someone explain to me why you can\'t pass a key as reference?

Ex:

if(is_array($where)){
    foreach($where as &$key => &$value){
              


        
2条回答
  •  Happy的楠姐
    2021-01-18 03:14

    Can someone explain to me why you can't pass a key as reference?

    Because the language does not support this. You'd be hard-pressed to find this ability in most languages, hence the term key.

    So am I stuck with something like this?

    Yes. The best way is to create a new array with the appropriate keys.

    Any alternatives?

    The only way to provide better alternatives is to know your specific situation. If your keys map to table column names, then the best approach is to leave the keys as is and escape them at their time of use in your SQL.

提交回复
热议问题