【问题标题】:Returning the deleted item after using array_pop [duplicate]使用array_pop后返回已删除的项目[重复]
【发布时间】:2019-09-12 03:04:39
【问题描述】:

这是我的数组:

$my_array = array("1", "2", "3", "4", "5");

使用 shuffle($my_array)array_pop($my_array) 后如何返回已删除的项目?

我想要类似的东西: 删除的号码是:3

这是我的代码:

$my_array = array("1", "2", "3", "4", "5");
shuffle($my_array)
array_pop($my_array)

我怎样才能做到这一点?

【问题讨论】:

    标签: php arrays


    【解决方案1】:

    根据 PHP 文档,array_pop() 将返回被删除的值:

    Return Values
    
    Returns the value of the last element of array. If array is empty (or is not an array), NULL will be returned.
    

    所以,您可以这样做:

    $my_array = array(1, 2, 3, 4, 5);
    shuffle($my_array);
    echo 'The deleted number is: <b>'.array_pop($my_array).'</b>';
    

    【讨论】:

      猜你喜欢
      • 2011-06-01
      • 2017-07-10
      • 1970-01-01
      • 2016-10-31
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      相关资源
      最近更新 更多