php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64192 function array_splice() wrong result
Submitted: 2013-02-12 00:20 UTC Modified: 2013-02-21 05:44 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: italopaesano at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.21 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: italopaesano at gmail dot com
New email:
PHP Version: OS:

 

 [2013-02-12 00:20 UTC] italopaesano at gmail dot com
Description:
------------
function array_splice()

 return wrong result when splice multidimensional array.
i hope that the attached script is clear.
sorry for my english.

Test script:
---------------
$a = array();
$a[] = array(
          'start' => array('day' => '1','month '=> '2'),
          'end'   => array('day'=> '3','month'=> '2'));
$a[] = array(
          'start' => array('day' => '1','month '=> '3'),
          'end'   => array('day'=> '3','month'=> '3'));

$strip = array(
          'start' => array('day' => '11','month '=> '1'),
          'end'   => array('day'=> '14','month'=> '1'));

array_splice($a, 0, 1, $strip);

$temp = print_r($a,TRUE);  
$temp = str_replace("\n", '<br>', $temp);
echo str_replace(" ", "&nbsp;",$temp);

Expected result:
----------------
Array
(
    [0] => Array
        (
            [start] => Array
                (
                    [day] => 11
                    [month ] => 1
                )

            [end] => Array
                (
                    [day] => 14
                    [month] => 1
                )

        )

    [1] => Array
        (
            [start] => Array
                (
                    [day] => 1
                    [month ] => 3
                )

            [end] => Array
                (
                    [day] => 3
                    [month] => 3
                )

        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [day] => 11
            [month ] => 1
        )

    [1] => Array
        (
            [day] => 14
            [month] => 1
        )

    [2] => Array
        (
            [start] => Array
                (
                    [day] => 1
                    [month ] => 3
                )

            [end] => Array
                (
                    [day] => 3
                    [month] => 3
                )

        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-21 05:44 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

the replacement is an array, and the elements are insert into the gap one by one.

for you need, you should change the $stripe to:
$strip = array(
    array(
          'start' => array('day' => '11','month '=> '1'),
          'end'   => array('day'=> '14','month'=> '1')),
);
 [2013-02-21 05:44 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC