- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试删除最后一个数组的第一个元素
数组:
$harbours = array(
'67' => array('boat1', 'boat2'),
'43' => array('boat3', 'boat4')
);
我想删除并返回 boat3
$last = end($harbours);
$boat = array_shift($last);
如果我然后 print_r ($harbours)
,'boat3' 仍然存在。
最佳答案
那是因为在 array_shift
中,您正在更改结束数组的副本。
您需要获取结束数组的引用才能移动它。
试试这个:
end($array);
$currKey = key($array); //get the last key
array_shift($array[$currKey]);
关于php - array_shift 来自数组中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13953706/
我得到了这个简单的例子来说明我遇到了什么问题。 假设你有: $myArray = array("A","B","C","D","E","F","I","G","H"); 目标是在循环中删除此数组的第
我的数组如下所示: $arValues = array( 345 => "jhdrfr", 534 => "jhdrffr", 673 => "jhrffr", 234 => "jfrhfr" );
我正在尝试删除最后一个数组的第一个元素 数组: $harbours = array( '67' => array('boat1', 'boat2'),
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章PHP array_shift()用法实例分析由作者收集整理,如果你对这
下面,调用箭头函数时,为什么我只得到第一个条目? array_shift($stack); var_dump($fruit()); var_dump($fruit()); var_dump($fru
好的,我需要在这个数组中保留键,我只想从这个数组中移动第一个元素。实际上我知道当我这样做时这个数组的第一个键总是 1: // Sort it by 1st group and 1st layout.
我正在创建一个数组并想删除数组的第一个元素并重新索引它。据我所知, array_shift() 是正确的解决方案。但是,它在我的实现中不起作用。 我有一个类的成员变量,它被定义为一个名为 $waypo
我正在尝试选择带有 col1 - col3 的表。我需要使用 array_shift 消除 col2 row1。这是我的代码: $data = array(); while ($row = mysql
当我尝试通过 verify_user 方法验证用户数据时 escape_string($username); $password = $database->escape_string($pas
我的代码可以追溯到 2011 年,而且我在代码布局方式的严格标准方面遇到了很多错误。 if (!isset($End)) { $Info['Ca
这个问题在这里已经有了答案: Only variables should be passed by reference (12 个回答) 6年前关闭。 我有一个错误: 严格的标准:只有变量应该通过引用
你会用哪个? 基本上我只想从数组中获取第一个元素,仅此而已。 最佳答案 嗯,他们做不同的事情。 array_shift($arr)从数组中取出第一个元素,并将其提供给您。 $arr[0] 只是给你..
我有一个数组中的文件列表,其中文件名是键,值是以秒为单位的最后修改日期。它们从最旧到最新排序。 文件被 glob() 放入,然后使用这种方式排序 asort($fileNameToLastModifi
重新开放: 因为 PHP 是一种服务器端语言,所以我假设我使用的浏览器并不重要,但显然不是这样。我一直只使用谷歌浏览器。 我在我的本地机器上安装了 WAMP,所以我可以在本地测试它,看看它是否与我的共
array_shift() expects parameter 1 to be array, null given in /home5/.../php/symfony/command/sfComman
我是一名优秀的程序员,十分优秀!