dongqiu8375 2016-12-15 07:09
浏览 12
已采纳

在不使用循环的情况下,在PHP的数组的最后设置“其他”值

I have tried to set "Other" value at last of array without using any looping. The array looks like:

array
(
[15] => Business Copywriting & Press Releases
[11] => Business Plans
[20] => Languages
[17] => Legal Writing
[19] => **Other**
[10] => Presentation Design
[13] => Proof reading & Editing
[16] => RESEARCH & SUMMARIES
[12] => RESUMES & COVER LETTERS
[18] => Transcriptions
[14] => Translating
)
  • 写回答

4条回答 默认 最新

  • dongwen2896 2016-12-15 07:28
    关注

    from what i'm understand, you want to move **Other** to the end of an array.

    Maybe this can help.

    $key = array_search ('**Other**', $arr);
    unset($arr[$key]); // remove **other**
    
    array_push($arr, "**Others**"); // put **Other** in the end of array
    

    but if you want to keep your array key, you cannot using array_push() but this will do;

    $key = array_search ('**Other**', $arr);
    unset($arr[$key]); // remove **other**
    
    $arr[$key] = '**Other**';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探