note 39643 added to function.array-splice

From: Date: Thu, 05 Feb 2004 19:16:20 +0000
Subject: note 39643 added to function.array-splice
Groups: php.notes 
Request: Send a blank email to php-notes+get-64699@lists.php.net to get a copy of this message
While trying to find a way to insert some array into another at some index, array_splice seemed like the function that I wanted. The results weren't quite as expected though. Of course, I can be using it wrong. My desired results turned out be $array1 after calling array_splice() and no tuning got me to have $array3 with what was showing up in $array1. [code] $array1 = array(1, 2, 3, 7, 8, 9); $array2 = array(4, 5, 6); echo '<br />array1 :: '; print_r( $array1 ); echo '<br />array2 :: '; print_r( $array2 ); $index = 3; // $length = count($array1); // $length = -1; $length = 0; // array1 is call by reference it seems $array3 = array_splice($array1, $index, $length, $array2); echo '<br />array1 :: '; print_r( $array1 ); echo '<br />array2 :: '; print_r( $array2 ); echo '<br />array3 :: '; print_r( $array3 ); [/code] Results in [code] array1 :: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 7 [4] => 8 [5] => 9 ) array2 :: Array ( [0] => 4 [1] => 5 [2] => 6 ) array1 :: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 ) array2 :: Array ( [0] => 4 [1] => 5 [2] => 6 ) array3 :: Array ( ) [/code] Cheers, Michael ---- Manual Page -- http://www.php.net/manual/en/function.array-splice.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39643 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39643&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39643&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64699) next »