I have an array in php

我在php中有一个数组

<?php
$array=array("a"=>"123","b"=>"234","c"=>"345");
array_shift($array);
//array("0"=>"234","1"=>"345");
?>

If I use this function, then key value gets changed. I want my key value to remain the same. How can I remove first element without affecting array key values. My answer should be like

如果我使用此功能,则键值会发生变化。我希望我的键值保持不变。如何在不影响数组键值的情况下删除第一个元素。我的回答应该是这样的

array("b"=>"234","c"=>"345");

Note:Please do not use foreach(); I want to do this by existing array functions in php

注意:请不要使用foreach();我想通过php中现有的数组函数来做到这一点

array_splice function is working for above array. But consider the below array

array_splice函数适用于上面的数组。但请考虑以下数组

<?php
$array = Array
(
    '39' => Array
        (
            'id' => '39',
            'field_id' => '620'

        ),

    '40' => Array
        (
            'id' => '40',
            'field_id' => '620',
            'default_value' => 'rrr',

));

array_splice($array, 0, 1);
print_r($array);
?>

It is showing answer as follows:

它的答案如下:

Array ( [0] => Array ( [id] => 40 [field_id] => 620 [default_value] => rrr ) )

May I know the reason?? Will array_splice() work only for single dimensional array?? Now key value is reset...

我可以知道原因吗? array_splice()只适用于单维数组吗?现在键值被重置......

4 个解决方案

#1


29

In case you do not know what the first item's key is:

如果你不知道第一项的关键是什么:

// Make sure to reset the array's current index
reset($array);

$key = key($array);
unset($array[$key]);

更多相关文章

  1. PHP中类和对象的相关函数
  2. php函数 什么时候使用fflush函数
  3. 以完整二叉树,数组格式获取所有节点
  4. php 写一个算法,查寻数组里第一个大于某数的值。
  5. 插入PHP数组作为MYSQL列
  6. 如何调试UPDATE函数在PHP中无法正常工作的原因?
  7. PHP结束后执行函数
  8. php把从数据库读取出来的数据存放到数组里
  9. 在key/value的基础上将数组分组到另一个数组中

随机推荐

  1. Android KitKat 4.4 Wifi移植之AP模式与
  2. Android基础笔记(二)-数据存储和界面展现
  3. Android 页面惯性回弹效果,Nested接口接口
  4. Android(安卓)多媒体扫描过程
  5. Android(安卓)HorizontalScrollView嵌套C
  6. android studio 程序员有福了—从layout
  7. Android设计模式-原型模式
  8. android 开发实现静默安装
  9. 数据存储之——Android内、外存储分区&常
  10. Andriod开发必备资料