note 37278 modified in function.array-unshift by vrana

From: Date: Tue, 17 Aug 2004 14:51:51 +0000
Subject: note 37278 modified in function.array-unshift by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79954@lists.php.net to get a copy of this message
Since deprecation of call-time pass-by-reference, you can not unshift with a reference : <?php array_unshift ($a, &$v); ?> If you'd like to unshift only one reference, here is a replacement function : <?php function array_unshift1 (& $iArray, $iValueWrappedInAnArray) { $lNewArray = false; foreach (array_keys ($iArray) as $lKey) $lNewArray[$lKey+1] = $iArray[$lKey]; $iArray = array (& $iValueWrappedInAnArray[0]); foreach ($lNewArray as $lValue) $iArray[] = $lValue; return count($iArray); } ?> instead, you'll now call : <?php array_unshift1 ($a, array (&$v)); ?> for further implications of this rude deprecation, you can read http://masterofweb.com/index.php?itemid=102 (this is not my text) --was-- Since deprecation of call-time pass-by-reference, you can not unshift with a reference : array_unshift ($a, &$v); If you'd like to unshift only one reference, here is a replacement function : function array_unshift1 (& $iArray, $iValueWrappedInAnArray) { $lNewArray = false; foreach (array_keys ($iArray) as $lKey) $lNewArray[$lKey+1] = $iArray[$lKey]; $iArray = array (& $iValueWrappedInAnArray[0]); foreach ($lNewArray as $lValue) $iArray[] = $lValue; return count($iArray); } instead, you'll now call : array_unshift1 ($a, array (&$v)); for further implications of this rude deprecation, you can read http://masterofweb.com/index.php?itemid=102 (this is not my text) http://php.net/manual/en/function.array-unshift.php

« previous php.notes (#79954) next »